diff --git a/block-storage/src/main/java/org/lucares/pdb/map/PersistentMap.java b/block-storage/src/main/java/org/lucares/pdb/map/PersistentMap.java index 44dac17..09a1aaf 100644 --- a/block-storage/src/main/java/org/lucares/pdb/map/PersistentMap.java +++ b/block-storage/src/main/java/org/lucares/pdb/map/PersistentMap.java @@ -141,20 +141,20 @@ public class PersistentMap implements AutoCloseable { } } - public void putAllValues(final Map map) throws IOException { + public synchronized void putAllValues(final Map map) throws IOException { for (final Entry e : map.entrySet()) { putValue(e.getKey(), e.getValue()); } } - public V putValue(final K key, final V value) throws IOException { + public synchronized V putValue(final K key, final V value) throws IOException { final byte[] encodedKey = keyEncoder.encode(key); final byte[] encodedValue = valueEncoder.encode(value); final byte[] oldValue = putValue(encodedKey, encodedValue); return oldValue == null ? null : valueEncoder.decode(oldValue); } - public V getValue(final K key) throws IOException { + public synchronized V getValue(final K key) throws IOException { final byte[] encodedKey = keyEncoder.encode(key); final byte[] foundValue = getValue(encodedKey); return foundValue == null ? null : valueEncoder.decode(foundValue); @@ -311,7 +311,7 @@ public class PersistentMap implements AutoCloseable { diskBlock.force(); } - public void print() throws IOException { + public synchronized void print() throws IOException { visitNodeEntriesPreOrder((node, parentNode, nodeEntry, depth) -> { @@ -324,7 +324,7 @@ public class PersistentMap implements AutoCloseable { }); } - public void visitNodeEntriesPreOrder(final VisitorCallback visitor) throws IOException { + public synchronized void visitNodeEntriesPreOrder(final VisitorCallback visitor) throws IOException { final long rootNodeOffset = readNodeOffsetOfRootNode(); visitNodeEntriesPreOrderRecursively(rootNodeOffset, null, visitor, 0); } @@ -347,7 +347,7 @@ public class PersistentMap implements AutoCloseable { FIND, ITERATE } - public void visitValues(final K keyPrefix, final Visitor visitor) throws IOException { + public synchronized void visitValues(final K keyPrefix, final Visitor visitor) throws IOException { final byte[] encodedKeyPrefix = keyEncoder.encode(keyPrefix); final long rootNodeOffset = readNodeOffsetOfRootNode();