adoroszlai commented on a change in pull request #2938:
URL: https://github.com/apache/ozone/pull/2938#discussion_r773247381
##########
File path:
hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/helpers/RepeatedOmKeyInfo.java
##########
@@ -66,7 +68,7 @@ public static RepeatedOmKeyInfo getFromProto(RepeatedKeyInfo
* @return
*/
public RepeatedKeyInfo getProto(boolean compact, int clientVersion) {
- List<KeyInfo> list = new ArrayList<>();
+ List<KeyInfo> list = new CopyOnWriteArrayList<>();
for(OmKeyInfo k : omKeyInfoList) {
Review comment:
Repro:
```java
@Test
public void threadSafety() throws InterruptedException {
final OmKeyInfo key = getKeyInfo(1);
final RepeatedOmKeyInfo subject = new RepeatedOmKeyInfo(key);
final RepeatedOmKeyInfoCodec codec = new RepeatedOmKeyInfoCodec(true);
final AtomicBoolean failed = new AtomicBoolean();
ThreadFactory threadFactory = new ThreadFactoryBuilder().setDaemon(true)
.build();
threadFactory.newThread(() -> {
for (int i = 0; i < 1000000; i++) {
try {
codec.toPersistedFormat(subject);
} catch (Exception e) {
e.printStackTrace();
failed.set(true);
}
}
}).start();
threadFactory.newThread(() -> {
for (int i = 0; i < 10000; i++) {
subject.addOmKeyInfo(key);
}
}).start();
final long start = Time.monotonicNow();
while (!failed.get() && (Time.monotonicNow() - start < 5000)) {
Thread.sleep(100);
}
assertFalse(failed.get());
}
```
```
java.util.ConcurrentModificationException
at java.util.ArrayList$Itr.checkForComodification(ArrayList.java:909)
at java.util.ArrayList$Itr.next(ArrayList.java:859)
at
org.apache.hadoop.ozone.om.helpers.RepeatedOmKeyInfo.getProto(RepeatedOmKeyInfo.java:70)
at
org.apache.hadoop.ozone.om.codec.RepeatedOmKeyInfoCodec.toPersistedFormat(RepeatedOmKeyInfoCodec.java:50)
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]