Skip to content

Commit 36fd488

Browse files
authored
fix(meta-service): snapshot key count should be reset (#18718)
1 parent 513c10f commit 36fd488

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/meta/service/src/store/store_inner.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,9 @@ impl RaftStoreInner {
228228

229229
// Pipe entries to the writer.
230230
{
231+
// Count the user keys and expiration keys.
232+
let mut key_counts = BTreeMap::<String, u64>::new();
233+
231234
while let Some(ent) = strm
232235
.try_next()
233236
.await
@@ -236,11 +239,10 @@ impl RaftStoreInner {
236239
// The first 4 chars are key space, such as: "kv--/" or "exp-/"
237240
// Get the first 4 chars as key space.
238241
let prefix = &ent.0.as_str()[..4];
239-
let ks = sys_data.key_counts_mut();
240-
if let Some(count) = ks.get_mut(prefix) {
242+
if let Some(count) = key_counts.get_mut(prefix) {
241243
*count += 1;
242244
} else {
243-
ks.insert(prefix.to_string(), 1);
245+
key_counts.insert(prefix.to_string(), 1);
244246
}
245247

246248
tx.send(WriteEntry::Data(ent))
@@ -250,6 +252,11 @@ impl RaftStoreInner {
250252
raft_metrics::storage::incr_snapshot_written_entries();
251253
}
252254

255+
{
256+
let ks = sys_data.key_counts_mut();
257+
*ks = key_counts;
258+
}
259+
253260
tx.send(WriteEntry::Finish((snapshot_id.clone(), sys_data)))
254261
.await
255262
.map_err(|e| StorageError::write_snapshot(Some(signature.clone()), &e))?;

0 commit comments

Comments
 (0)