This is an automated email from the ASF dual-hosted git repository.
madhan pushed a commit to branch ranger-2.2
in repository https://gitbox.apache.org/repos/asf/ranger.git
The following commit(s) were added to refs/heads/ranger-2.2 by this push:
new c336699 RANGER-3292: fixed ConcurrentModificationException from
RangerTransactionSynchronizationAdapter
c336699 is described below
commit c336699753729af5d850776763013956bfa740b4
Author: Chia-Ping Tsai <[email protected]>
AuthorDate: Sat May 29 14:46:27 2021 +0800
RANGER-3292: fixed ConcurrentModificationException from
RangerTransactionSynchronizationAdapter
Signed-off-by: Madhan Neethiraj <[email protected]>
(cherry picked from commit 9c6969de882e9c1e63ebbc4f250a0ee2624be7d5)
---
.../RangerTransactionSynchronizationAdapter.java | 10 +++--
...estRangerTransactionSynchronizationAdapter.java | 47 ++++++++++++++++++++++
2 files changed, 53 insertions(+), 4 deletions(-)
diff --git
a/security-admin/src/main/java/org/apache/ranger/common/db/RangerTransactionSynchronizationAdapter.java
b/security-admin/src/main/java/org/apache/ranger/common/db/RangerTransactionSynchronizationAdapter.java
index 7349898..fc44e6d 100644
---
a/security-admin/src/main/java/org/apache/ranger/common/db/RangerTransactionSynchronizationAdapter.java
+++
b/security-admin/src/main/java/org/apache/ranger/common/db/RangerTransactionSynchronizationAdapter.java
@@ -118,14 +118,16 @@ public class RangerTransactionSynchronizationAdapter
extends TransactionSynchron
final boolean isParentTransactionCommitted = status ==
STATUS_COMMITTED;
if (isParentTransactionCommitted) {
- // Run tasks scheduled to run after transaction is successfully
committed
- runRunnables(RUNNABLES_AFTER_COMMIT.get(), true);
+ List<Runnable> runnablesAfterCommit = RUNNABLES_AFTER_COMMIT.get();
RUNNABLES_AFTER_COMMIT.remove();
+ // Run tasks scheduled to run after transaction is successfully
committed
+ runRunnables(runnablesAfterCommit, true);
}
- // Run other tasks scheduled to run after transaction completes
- runRunnables(RUNNABLES.get(), false);
+ List<Runnable> runnables = RUNNABLES.get();
RUNNABLES.remove();
+ // Run other tasks scheduled to run after transaction completes
+ runRunnables(runnables, false);
if (LOG.isDebugEnabled()) {
LOG.debug("<==
RangerTransactionSynchronizationAdapter.afterCompletion(status=" + (status ==
STATUS_COMMITTED ? "COMMITTED" : "ROLLED_BACK") + ")");
diff --git
a/security-admin/src/test/java/org/apache/ranger/common/db/TestRangerTransactionSynchronizationAdapter.java
b/security-admin/src/test/java/org/apache/ranger/common/db/TestRangerTransactionSynchronizationAdapter.java
new file mode 100644
index 0000000..735c741
--- /dev/null
+++
b/security-admin/src/test/java/org/apache/ranger/common/db/TestRangerTransactionSynchronizationAdapter.java
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.ranger.common.db;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.mockito.Mockito;
+import org.springframework.transaction.PlatformTransactionManager;
+import
org.springframework.transaction.support.TransactionSynchronizationManager;
+
+import java.util.concurrent.atomic.AtomicInteger;
+
+public class TestRangerTransactionSynchronizationAdapter {
+
+ @Test
+ public void testNestedRunnableAfterCompletion() {
+ TransactionSynchronizationManager.initSynchronization();
+ try {
+ RangerTransactionSynchronizationAdapter rtsa = new
RangerTransactionSynchronizationAdapter();
+ rtsa.txManager = Mockito.mock(PlatformTransactionManager.class);
+ AtomicInteger count = new AtomicInteger(0);
+ rtsa.executeOnTransactionCompletion(() -> {
+ count.incrementAndGet();
+ rtsa.executeOnTransactionCompletion(count::incrementAndGet);
+ });
+ rtsa.afterCompletion(0);
+ Assert.assertEquals(1, count.get());
+ } finally {
+ TransactionSynchronizationManager.clear();
+ }
+
+ }
+}