mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
server: Implement compaction hash checking
Signed-off-by: Marek Siarkowicz <siarkowicz@google.com>
This commit is contained in:
@@ -93,6 +93,9 @@ type HashStorage interface {
|
||||
|
||||
// Store adds hash value in local cache, allowing it can be returned by HashByRev.
|
||||
Store(valueHash KeyValueHash)
|
||||
|
||||
// Hashes returns list of up to `hashStorageMaxSize` newest previously stored hashes.
|
||||
Hashes() []KeyValueHash
|
||||
}
|
||||
|
||||
type hashStorage struct {
|
||||
@@ -146,3 +149,14 @@ func (s *hashStorage) Store(hash KeyValueHash) {
|
||||
s.hashes = s.hashes[len(s.hashes)-hashStorageMaxSize:]
|
||||
}
|
||||
}
|
||||
|
||||
func (s *hashStorage) Hashes() []KeyValueHash {
|
||||
s.hashMu.RLock()
|
||||
// Copy out hashes under lock just to be safe
|
||||
hashes := make([]KeyValueHash, 0, len(s.hashes))
|
||||
for _, hash := range s.hashes {
|
||||
hashes = append(hashes, hash)
|
||||
}
|
||||
s.hashMu.RUnlock()
|
||||
return hashes
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user