You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ozone.apache.org by ca...@apache.org on 2021/12/24 02:11:54 UTC

[ozone] branch master updated: HDDS-6129. OM has thread unsafe issues that can cause OM shutdown. (#2938)

This is an automated email from the ASF dual-hosted git repository.

captainzmc pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ozone.git


The following commit(s) were added to refs/heads/master by this push:
     new 97143b8  HDDS-6129. OM has thread unsafe issues that can cause OM shutdown. (#2938)
97143b8 is described below

commit 97143b8f9407430a7e5a298b5514e468c09d80b2
Author: micah zhao <mi...@tencent.com>
AuthorDate: Fri Dec 24 10:11:31 2021 +0800

    HDDS-6129. OM has thread unsafe issues that can cause OM shutdown. (#2938)
    
    * fix concurrentModificationException in RepeatedOmKeyInfo
---
 .../hadoop/ozone/om/helpers/RepeatedOmKeyInfo.java |  4 +++
 .../ozone/om/codec/RepeatedOmKeyInfoCodec.java     |  2 +-
 .../ozone/om/codec/TestRepeatedOmKeyInfoCodec.java | 36 +++++++++++++++++++++-
 3 files changed, 40 insertions(+), 2 deletions(-)

diff --git a/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/helpers/RepeatedOmKeyInfo.java b/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/helpers/RepeatedOmKeyInfo.java
index 5c02085..cde8e39 100644
--- a/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/helpers/RepeatedOmKeyInfo.java
+++ b/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/helpers/RepeatedOmKeyInfo.java
@@ -93,4 +93,8 @@ public class RepeatedOmKeyInfo {
       return new RepeatedOmKeyInfo(omKeyInfos);
     }
   }
+
+  public RepeatedOmKeyInfo copyObject() {
+    return new RepeatedOmKeyInfo(new ArrayList<>(omKeyInfoList));
+  }
 }
diff --git a/hadoop-ozone/interface-storage/src/main/java/org/apache/hadoop/ozone/om/codec/RepeatedOmKeyInfoCodec.java b/hadoop-ozone/interface-storage/src/main/java/org/apache/hadoop/ozone/om/codec/RepeatedOmKeyInfoCodec.java
index facb5c9..2c1d46e 100644
--- a/hadoop-ozone/interface-storage/src/main/java/org/apache/hadoop/ozone/om/codec/RepeatedOmKeyInfoCodec.java
+++ b/hadoop-ozone/interface-storage/src/main/java/org/apache/hadoop/ozone/om/codec/RepeatedOmKeyInfoCodec.java
@@ -65,6 +65,6 @@ public class RepeatedOmKeyInfoCodec implements Codec<RepeatedOmKeyInfo> {
 
   @Override
   public RepeatedOmKeyInfo copyObject(RepeatedOmKeyInfo object) {
-    return object;
+    return object.copyObject();
   }
 }
diff --git a/hadoop-ozone/interface-storage/src/test/java/org/apache/hadoop/ozone/om/codec/TestRepeatedOmKeyInfoCodec.java b/hadoop-ozone/interface-storage/src/test/java/org/apache/hadoop/ozone/om/codec/TestRepeatedOmKeyInfoCodec.java
index f89477c..d356552 100644
--- a/hadoop-ozone/interface-storage/src/test/java/org/apache/hadoop/ozone/om/codec/TestRepeatedOmKeyInfoCodec.java
+++ b/hadoop-ozone/interface-storage/src/test/java/org/apache/hadoop/ozone/om/codec/TestRepeatedOmKeyInfoCodec.java
@@ -18,6 +18,7 @@
 
 package org.apache.hadoop.ozone.om.codec;
 
+import com.google.common.util.concurrent.ThreadFactoryBuilder;
 import org.apache.hadoop.hdds.client.BlockID;
 import org.apache.hadoop.hdds.client.RatisReplicationConfig;
 import org.apache.hadoop.hdds.protocol.proto.HddsProtos;
@@ -34,7 +35,10 @@ import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
+import java.util.concurrent.ThreadFactory;
+import java.util.concurrent.atomic.AtomicBoolean;
 
+import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.fail;
@@ -79,7 +83,8 @@ public class TestRepeatedOmKeyInfoCodec {
   }
 
   @Test
-  public void test() {
+  public void test() throws InterruptedException {
+    threadSafety();
     testWithoutPipeline(1);
     testWithoutPipeline(2);
     testCompatibility(1);
@@ -120,4 +125,33 @@ public class TestRepeatedOmKeyInfoCodec {
       fail("Should success");
     }
   }
+
+  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.copyObject());
+        } 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());
+  }
 }

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@ozone.apache.org
For additional commands, e-mail: commits-help@ozone.apache.org