From 1a907f3f88e72645df7e1e9e796262659f9b1ba1 Mon Sep 17 00:00:00 2001 From: Zhang Yifei Date: Thu, 22 Aug 2024 11:57:06 +0800 Subject: [PATCH] Reset state with snapshots --- src/org/jgroups/raft/blocks/CounterService.java | 1 + src/org/jgroups/raft/blocks/ReplicatedStateMachine.java | 1 + 2 files changed, 2 insertions(+) diff --git a/src/org/jgroups/raft/blocks/CounterService.java b/src/org/jgroups/raft/blocks/CounterService.java index 4566faf5..f0b5f124 100644 --- a/src/org/jgroups/raft/blocks/CounterService.java +++ b/src/org/jgroups/raft/blocks/CounterService.java @@ -169,6 +169,7 @@ public void writeContentTo(DataOutput out) throws Exception { @Override public void readContentFrom(DataInput in) throws Exception { synchronized (counters) { + counters.clear(); int size = in.readInt(); for (int i = 0; i < size; i++) { AsciiString name = Bits.readAsciiString(in); diff --git a/src/org/jgroups/raft/blocks/ReplicatedStateMachine.java b/src/org/jgroups/raft/blocks/ReplicatedStateMachine.java index 92e73589..e199b637 100644 --- a/src/org/jgroups/raft/blocks/ReplicatedStateMachine.java +++ b/src/org/jgroups/raft/blocks/ReplicatedStateMachine.java @@ -237,6 +237,7 @@ public int size() { tmp.put(key, val); } synchronized(map) { + map.clear(); map.putAll(tmp); } }