The new implementation:
- Uses map to track unique keys for accurate counting
- Excludes internal built-in keys from total count
- Improves code maintainability
Although this approach uses additional memory for the map, the trade-off
is acceptable since:
- Status() is not in hot path
- Correctness takes priority over performance optimization
- Simpler code is easier to maintain
Fixes#19253
Signed-off-by: Xiang Ji <johnsmith.jix@gmail.com>
The tombstone could be the only one available revision in database.
It happens when all historical revisions have been deleted in previous
compactions. Since tombstone revision is still in database, we should
restore it as valid key index. Otherwise, we lost that event.
Signed-off-by: Wei Fu <fuweid89@gmail.com>
* etcdserver: rename `minimumBatchInterval` to `defaultCompactionSleepInterval` and `defaultCompactBatchLimit` to `defaultCompactionBatchLimit`
Signed-off-by: Jalin Wang <JalinWang@outlook.com>
Before this patch, the tombstone can be deleted if its revision is equal
compacted revision. It causes that the watch subscriber won't get this
DELETE event. Based on Compact API[1], we should keep tombstone revision
if it's not less than the compaction revision.
> CompactionRequest compacts the key-value store up to a given revision.
> All superseded keys with a revision less than the compaction revision
> will be removed.
[1]: https://etcd.io/docs/latest/dev-guide/api_reference_v3/
Signed-off-by: Wei Fu <fuweid89@gmail.com>
In commit [[1]], the newTestKeyIndex function creates one key with two
Revision{Main: 14} revisions. However, starting from version [[2]], etcd server
does not allow duplicate keys in a single transaction. This update to
newTestKeyIndex is to avoid confusion and ensure consistency with the
latest etcd server behavior.
REF:
[1]: be80d11948
[2]: https://github.com/etcd-io/etcd/pull/4376
Signed-off-by: Wei Fu <fuweid89@gmail.com>
golangci-lint reports the following issue:
storage/mvcc/kvstore.go:312:27: (*store).restore - result 0 (error) is always nil (unparam)
It's due to the fact that both Attach() and compactLockfree() within the
function restore() are able to return an error, but we only log them in
the current implementation. Thus, the return value restore() is always
nil, hence the linter warning.
We have agreed to suppress the linter warning for now [1].
Reference:
[1] https://github.com/etcd-io/etcd/pull/18228#issuecomment-2187309957
Signed-off-by: Chun-Hung Tseng <henrybear327@gmail.com>
scheduleCompaction function
To improve traceability of backend database usage, Added below parameter
related to backend database usage metrics inside scheduledCompaction
function.
current-db-size-bytes
current-db-size
current-db-size-in-use-bytes
current-db-size-in-use
Signed-off-by: Rahul More <rahulbapumore@gmail.com>