Skip to content

Commit 3c445d0

Browse files
committed
synchronized
1 parent ecc80ae commit 3c445d0

1 file changed

Lines changed: 11 additions & 11 deletions

File tree

‎src/main/java/org/tron/core/db2/core/SnapshotRoot.java‎

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public SnapshotRoot(String parentName, String name) {
2323
}
2424

2525
@Override
26-
public byte[] get(byte[] key) {
26+
public synchronized byte[] get(byte[] key) {
2727
Value value = cache.get(Key.of(key));
2828
if (value != null) {
2929
return value.getBytes();
@@ -33,21 +33,21 @@ public byte[] get(byte[] key) {
3333
}
3434

3535
@Override
36-
public void put(byte[] key, byte[] value) {
36+
public synchronized void put(byte[] key, byte[] value) {
3737
cache.put(Key.of(key), Value.copyOf(Operator.MODIFY, value));
3838
}
3939

4040
@Override
41-
public void remove(byte[] key) {
41+
public synchronized void remove(byte[] key) {
4242
cache.put(Key.of(key), Value.of(Operator.DELETE, null));
4343
}
4444

4545
@Override
46-
public void merge(Snapshot from) {
46+
public synchronized void merge(Snapshot from) {
4747
cache.putAll(((SnapshotImpl) from).db.asMap());
4848
}
4949

50-
public void flush() {
50+
public synchronized void flush() {
5151
Map<WrappedByteArray, WrappedByteArray> batch = new HashMap<>((int) cache.size());
5252
Streams.stream(cache)
5353
.map(e -> Maps.immutableEntry(WrappedByteArray.of(e.getKey().getBytes()),
@@ -58,22 +58,22 @@ public void flush() {
5858
}
5959

6060
@Override
61-
public Snapshot retreat() {
61+
public synchronized Snapshot retreat() {
6262
return this;
6363
}
6464

6565
@Override
66-
public Snapshot getRoot() {
66+
public synchronized Snapshot getRoot() {
6767
return this;
6868
}
6969

7070
@Override
71-
public Snapshot getSolidity() {
71+
public synchronized Snapshot getSolidity() {
7272
return this;
7373
}
7474

7575
@Override
76-
public Iterator<Map.Entry<byte[],byte[]>> iterator() {
76+
public synchronized Iterator<Map.Entry<byte[],byte[]>> iterator() {
7777
return Iterators.concat(
7878
Iterators.transform(
7979
Iterators.filter(cache.iterator(), e -> e.getValue().getBytes() != null),
@@ -82,12 +82,12 @@ public Iterator<Map.Entry<byte[],byte[]>> iterator() {
8282
}
8383

8484
@Override
85-
public void close() {
85+
public synchronized void close() {
8686
((LevelDB) db).close();
8787
}
8888

8989
@Override
90-
public void reset() {
90+
public synchronized void reset() {
9191
((LevelDB) db).reset();
9292
}
9393
}

0 commit comments

Comments
 (0)