[fix](meta) fix ConcurrentModificationException when dump image (#28072)

```
Caused by: java.util.ConcurrentModificationException
        at java.util.HashMap$HashIterator.nextNode(HashMap.java:1437) ~[?:1.8.0_131]
        at java.util.HashMap$EntryIterator.next(HashMap.java:1471) ~[?:1.8.0_131]
        at java.util.HashMap$EntryIterator.next(HashMap.java:1469) ~[?:1.8.0_131]
        at org.apache.doris.catalog.CatalogRecycleBin.write(CatalogRecycleBin.java:1047) ~[doris-fe.jar:1.2-SNAPSHOT]
        at org.apache.doris.catalog.Env.saveRecycleBin(Env.java:2298) ~[doris-fe.jar:1.2-SNAPSHOT]
```

When calling `/dump` api to dump image, ConcurrentModificationException may be thrown.
Because no lock to protect `CatalogRecycleBin`
This commit is contained in:
Mingyu Chen
2023-12-07 18:26:02 +08:00
committed by GitHub
parent 3dcbf16404
commit 34642781c2

View File

@ -1033,8 +1033,10 @@ public class CatalogRecycleBin extends MasterDaemon implements Writable {
return Stream.of(dbInfos, tableInfos, partitionInfos).flatMap(Collection::stream).collect(Collectors.toList());
}
// Need to add "synchronized", because when calling /dump api to dump image,
// this class is not protected by any lock, will throw ConcurrentModificationException.
@Override
public void write(DataOutput out) throws IOException {
public synchronized void write(DataOutput out) throws IOException {
int count = idToDatabase.size();
out.writeInt(count);
for (Map.Entry<Long, RecycleDatabaseInfo> entry : idToDatabase.entrySet()) {