From eb027d4830aa63d3579bcd133b2a18c860bccdcf Mon Sep 17 00:00:00 2001 From: wen_yi Date: Mon, 27 Jul 2020 18:12:25 +0800 Subject: [PATCH 01/10] HBASE-24665 --- .../hadoop/hbase/regionserver/LogRoller.java | 105 ++++++++++++----- .../hbase/regionserver/TestLogRoller.java | 109 ++++++++++++++++++ 2 files changed, 187 insertions(+), 27 deletions(-) create mode 100644 hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestLogRoller.java diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/LogRoller.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/LogRoller.java index fd208c25b069..824bd4f42bc6 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/LogRoller.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/LogRoller.java @@ -56,23 +56,27 @@ public class LogRoller extends HasThread { private static final Log LOG = LogFactory.getLog(LogRoller.class); private final ReentrantLock rollLock = new ReentrantLock(); private final AtomicBoolean rollLog = new AtomicBoolean(false); - private final ConcurrentHashMap walNeedsRoll = - new ConcurrentHashMap(); + private final ConcurrentHashMap wals = + new ConcurrentHashMap(); private final Server server; protected final RegionServerServices services; - private volatile long lastrolltime = System.currentTimeMillis(); // Period to roll log. - private final long rollperiod; + private final long rollPeriod; private final int threadWakeFrequency; // The interval to check low replication on hlog's pipeline - private long checkLowReplicationInterval; + private final long checkLowReplicationInterval; public void addWAL(final WAL wal) { - if (null == walNeedsRoll.putIfAbsent(wal, Boolean.FALSE)) { + if (null == wals.putIfAbsent(wal, new RollController(wal))) { wal.registerWALActionsListener(new WALActionsListener.Base() { @Override public void logRollRequested(WALActionsListener.RollRequestReason reason) { - walNeedsRoll.put(wal, Boolean.TRUE); + RollController controller = wals.get(wal); + if (controller == null) { + controller = new RollController(wal); + wals.put(wal, controller); + } + controller.requestRoll(); // TODO logs will contend with each other here, replace with e.g. DelayedQueue synchronized(rollLog) { rollLog.set(true); @@ -84,8 +88,8 @@ public void logRollRequested(WALActionsListener.RollRequestReason reason) { } public void requestRollAll() { - for (WAL wal : walNeedsRoll.keySet()) { - walNeedsRoll.put(wal, Boolean.TRUE); + for (RollController controller : wals.values()) { + controller.requestRoll(); } synchronized(rollLog) { rollLog.set(true); @@ -98,7 +102,7 @@ public LogRoller(final Server server, final RegionServerServices services) { super("LogRoller"); this.server = server; this.services = services; - this.rollperiod = this.server.getConfiguration(). + this.rollPeriod = this.server.getConfiguration(). getLong("hbase.regionserver.logroll.period", 3600000); this.threadWakeFrequency = this.server.getConfiguration(). getInt(HConstants.THREAD_WAKE_FREQUENCY, 10 * 1000); @@ -120,9 +124,9 @@ public void interrupt() { */ void checkLowReplication(long now) { try { - for (Entry entry : walNeedsRoll.entrySet()) { + for (Entry entry : wals.entrySet()) { WAL wal = entry.getKey(); - boolean neeRollAlready = entry.getValue(); + boolean neeRollAlready = entry.getValue().needsRoll(now); if(wal instanceof FSHLog && !neeRollAlready) { FSHLog hlog = (FSHLog)wal; if ((now - hlog.getLastTimeCheckLowReplication()) @@ -141,9 +145,14 @@ public void run() { while (!server.isStopped()) { long now = System.currentTimeMillis(); checkLowReplication(now); - boolean periodic = false; if (!rollLog.get()) { - periodic = (now - this.lastrolltime) > this.rollperiod; + boolean periodic = false; + for (RollController controller : wals.values()) { + if (controller.needsPeriodicRoll(now)) { + periodic = true; + break; + } + } if (!periodic) { synchronized (rollLog) { try { @@ -156,23 +165,24 @@ public void run() { } continue; } - // Time for periodic roll - if (LOG.isDebugEnabled()) { - LOG.debug("Wal roll period " + this.rollperiod + "ms elapsed"); - } - } else if (LOG.isDebugEnabled()) { - LOG.debug("WAL roll requested"); } rollLock.lock(); // FindBugs UL_UNRELEASED_LOCK_EXCEPTION_PATH try { - this.lastrolltime = now; - for (Entry entry : walNeedsRoll.entrySet()) { + for (Entry entry : wals.entrySet()) { final WAL wal = entry.getKey(); + RollController controller = entry.getValue(); + if (controller.isRollRequested()) { + // WAL roll requested, fall through + LOG.debug("WAL " + wal + " roll requested"); + } else if (controller.needsPeriodicRoll(now)) { + // Time for periodic roll, fall through + LOG.debug("WAL " + wal + " roll period " + this.rollPeriod + "ms elapsed"); + } else { + continue; + } // Force the roll if the logroll.period is elapsed or if a roll was requested. // The returned value is an array of actual region names. - final byte [][] regionsToFlush = wal.rollWriter(periodic || - entry.getValue().booleanValue()); - walNeedsRoll.put(wal, Boolean.FALSE); + final byte [][] regionsToFlush = controller.rollWal(now); if (regionsToFlush != null) { for (byte [] r: regionsToFlush) scheduleFlush(r); } @@ -229,11 +239,52 @@ private void scheduleFlush(final byte [] encodedRegionName) { */ @VisibleForTesting public boolean walRollFinished() { - for (boolean needRoll : walNeedsRoll.values()) { - if (needRoll) { + long now = System.currentTimeMillis(); + for (RollController controller : wals.values()) { + if (controller.needsRoll(now)) { return false; } } return true; } + + + /** + * Independently control the roll of each wal. When use multiwal, + * can avoid all wal roll together. see HBASE-24665 for detail + */ + protected class RollController { + private final WAL wal; + private final AtomicBoolean rollRequest; + private long lastRollTime; + + RollController(WAL wal) { + this.wal = wal; + this.rollRequest = new AtomicBoolean(false); + this.lastRollTime = System.currentTimeMillis(); + } + + public void requestRoll() { + this.rollRequest.set(true); + } + + public byte[][] rollWal(long now) throws IOException { + this.lastRollTime = now; + byte[][] regionsToFlush = wal.rollWriter(true); + this.rollRequest.set(false); + return regionsToFlush; + } + + public boolean isRollRequested() { + return rollRequest.get(); + } + + public boolean needsPeriodicRoll(long now) { + return (now - this.lastRollTime) > rollPeriod; + } + + public boolean needsRoll(long now) { + return isRollRequested() || needsPeriodicRoll(now); + } + } } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestLogRoller.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestLogRoller.java new file mode 100644 index 000000000000..8a6211baabb2 --- /dev/null +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestLogRoller.java @@ -0,0 +1,109 @@ +/** + * + * 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.hadoop.hbase.regionserver; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; + +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.fs.FileSystem; +import org.apache.hadoop.fs.Path; +import org.apache.hadoop.hbase.HBaseTestingUtility; +import org.apache.hadoop.hbase.HConstants; +import org.apache.hadoop.hbase.regionserver.wal.FSHLog; +import org.apache.hadoop.hbase.testclassification.MediumTests; +import org.apache.hadoop.hbase.testclassification.RegionServerTests; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.experimental.categories.Category; +import org.mockito.Mockito; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; + +@Category({ RegionServerTests.class, MediumTests.class }) +public class TestLogRoller { + + private static final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility(); + + private static final int LOG_ROLL_PERIOD = 20 * 1000; + private static final String LOG_DIR = "WALs"; + private static final String ARCHIVE_DIR = "archiveWALs"; + private static final String WAL_PREFIX = "test-log-roller"; + private static Configuration CONF; + private static LogRoller ROLLER; + private static Path ROOT_DIR; + private static FileSystem FS; + + @Before public void setup() throws Exception { + CONF = TEST_UTIL.getConfiguration(); + CONF.setInt("hbase.regionserver.logroll.period", LOG_ROLL_PERIOD); + CONF.setInt(HConstants.THREAD_WAKE_FREQUENCY, 300); + ROOT_DIR = TEST_UTIL.getRandomDir(); + FS = FileSystem.get(CONF); + HRegionServer server = Mockito.mock(HRegionServer.class); + Mockito.when(server.getConfiguration()).thenReturn(CONF); + RegionServerServices services = Mockito.mock(RegionServerServices.class); + ROLLER = new LogRoller(server, services); + ROLLER.start(); + } + + @After public void tearDown() throws Exception { + ROLLER.interrupt(); + FS.close(); + TEST_UTIL.shutdownMiniCluster(); + } + + /** + * verify that each wal roll separately + */ + @Test public void testRequestRollWithMultiWal() throws Exception { + // add multiple wal + Map wals = new HashMap(); + for (int i = 1; i <= 3; i++) { + FSHLog wal = new FSHLog(FS, ROOT_DIR, LOG_DIR, ARCHIVE_DIR, CONF, null, + true, WAL_PREFIX, "." + i); + wals.put(wal, wal.getCurrentFileName()); + ROLLER.addWAL(wal); + Thread.sleep(1000); + } + + // request roll + Iterator> it = wals.entrySet().iterator(); + Map.Entry walEntry = it.next(); + walEntry.getKey().requestLogRoll(); + Thread.sleep(5000); + + assertNotEquals(walEntry.getValue(), walEntry.getKey().getCurrentFileName()); + walEntry.setValue(walEntry.getKey().getCurrentFileName()); + while (it.hasNext()) { + walEntry = it.next(); + assertEquals(walEntry.getValue(), walEntry.getKey().getCurrentFileName()); + } + + // period roll + Thread.sleep(LOG_ROLL_PERIOD + 5000); + for (Map.Entry entry : wals.entrySet()) { + assertNotEquals(entry.getValue(), entry.getKey().getCurrentFileName()); + entry.getKey().close(); + } + } +} From c68eeba5f8bfc0390bf5f0d54763e8446447e995 Mon Sep 17 00:00:00 2001 From: wen_yi Date: Tue, 4 Aug 2020 19:44:27 +0800 Subject: [PATCH 02/10] fix --- .../hadoop/hbase/regionserver/TestLogRoller.java | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestLogRoller.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestLogRoller.java index 8a6211baabb2..83d9f28901cc 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestLogRoller.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestLogRoller.java @@ -35,11 +35,12 @@ import org.junit.Test; import org.junit.experimental.categories.Category; import org.mockito.Mockito; + import java.util.HashMap; import java.util.Iterator; import java.util.Map; -@Category({ RegionServerTests.class, MediumTests.class }) +@Category({RegionServerTests.class, MediumTests.class}) public class TestLogRoller { private static final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility(); @@ -53,7 +54,8 @@ public class TestLogRoller { private static Path ROOT_DIR; private static FileSystem FS; - @Before public void setup() throws Exception { + @Before + public void setup() throws Exception { CONF = TEST_UTIL.getConfiguration(); CONF.setInt("hbase.regionserver.logroll.period", LOG_ROLL_PERIOD); CONF.setInt(HConstants.THREAD_WAKE_FREQUENCY, 300); @@ -66,7 +68,8 @@ public class TestLogRoller { ROLLER.start(); } - @After public void tearDown() throws Exception { + @After + public void tearDown() throws Exception { ROLLER.interrupt(); FS.close(); TEST_UTIL.shutdownMiniCluster(); @@ -75,12 +78,14 @@ public class TestLogRoller { /** * verify that each wal roll separately */ - @Test public void testRequestRollWithMultiWal() throws Exception { + @Test + public void testRequestRollWithMultiWal() throws Exception { // add multiple wal Map wals = new HashMap(); for (int i = 1; i <= 3; i++) { FSHLog wal = new FSHLog(FS, ROOT_DIR, LOG_DIR, ARCHIVE_DIR, CONF, null, - true, WAL_PREFIX, "." + i); + true, WAL_PREFIX, "." + i); + wal.rollWriter(true); wals.put(wal, wal.getCurrentFileName()); ROLLER.addWAL(wal); Thread.sleep(1000); From 32e723d06195332fb00a5abcdce6d94d43f6b716 Mon Sep 17 00:00:00 2001 From: wen_yi Date: Fri, 7 Aug 2020 09:52:01 +0800 Subject: [PATCH 03/10] fix --- .../apache/hadoop/hbase/regionserver/TestLogRoller.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestLogRoller.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestLogRoller.java index 83d9f28901cc..fac6b9936e7b 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestLogRoller.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestLogRoller.java @@ -22,6 +22,10 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotEquals; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; + import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; @@ -36,10 +40,6 @@ import org.junit.experimental.categories.Category; import org.mockito.Mockito; -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map; - @Category({RegionServerTests.class, MediumTests.class}) public class TestLogRoller { From 4e38b0de5ecd821a60a3e3fd124289a479651019 Mon Sep 17 00:00:00 2001 From: wen_yi Date: Fri, 7 Aug 2020 14:49:59 +0800 Subject: [PATCH 04/10] fix --- .../apache/hadoop/hbase/regionserver/LogRoller.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/LogRoller.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/LogRoller.java index 824bd4f42bc6..be9d9df8c1d2 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/LogRoller.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/LogRoller.java @@ -71,14 +71,14 @@ public void addWAL(final WAL wal) { wal.registerWALActionsListener(new WALActionsListener.Base() { @Override public void logRollRequested(WALActionsListener.RollRequestReason reason) { - RollController controller = wals.get(wal); - if (controller == null) { - controller = new RollController(wal); - wals.put(wal, controller); - } - controller.requestRoll(); // TODO logs will contend with each other here, replace with e.g. DelayedQueue synchronized(rollLog) { + RollController controller = wals.get(wal); + if (controller == null) { + controller = new RollController(wal); + wals.putIfAbsent(wal, controller); + } + controller.requestRoll(); rollLog.set(true); rollLog.notifyAll(); } From 12c5b196c7d7ad48268bf95fe60cbacd6cd823ca Mon Sep 17 00:00:00 2001 From: wen_yi Date: Mon, 10 Aug 2020 10:30:04 +0800 Subject: [PATCH 05/10] fix --- .../java/org/apache/hadoop/hbase/regionserver/LogRoller.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/LogRoller.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/LogRoller.java index be9d9df8c1d2..97630dc20d0e 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/LogRoller.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/LogRoller.java @@ -76,7 +76,7 @@ public void logRollRequested(WALActionsListener.RollRequestReason reason) { RollController controller = wals.get(wal); if (controller == null) { controller = new RollController(wal); - wals.putIfAbsent(wal, controller); + wals.put(wal, controller); } controller.requestRoll(); rollLog.set(true); From 7cc0dbff4ceded376d99b4d0f2d5b3a0e511bd05 Mon Sep 17 00:00:00 2001 From: wen_yi Date: Mon, 10 Aug 2020 14:29:29 +0800 Subject: [PATCH 06/10] fix --- .../hadoop/hbase/regionserver/LogRoller.java | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/LogRoller.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/LogRoller.java index 97630dc20d0e..42c03d8dd624 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/LogRoller.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/LogRoller.java @@ -71,14 +71,19 @@ public void addWAL(final WAL wal) { wal.registerWALActionsListener(new WALActionsListener.Base() { @Override public void logRollRequested(WALActionsListener.RollRequestReason reason) { + RollController controller = wals.get(wal); + if (controller == null) { + synchronized(wals) { + controller = wals.get(wal); + if (controller == null) { + controller = new RollController(wal); + wals.put(wal, controller); + } + } + } + controller.requestRoll(); // TODO logs will contend with each other here, replace with e.g. DelayedQueue synchronized(rollLog) { - RollController controller = wals.get(wal); - if (controller == null) { - controller = new RollController(wal); - wals.put(wal, controller); - } - controller.requestRoll(); rollLog.set(true); rollLog.notifyAll(); } From cff4dc111ca37a1bf63e328a74d487605ff8b82e Mon Sep 17 00:00:00 2001 From: wen_yi Date: Tue, 29 Sep 2020 15:09:12 +0800 Subject: [PATCH 07/10] HBASE-24665 --- .../org/apache/hadoop/hbase/regionserver/LogRoller.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/LogRoller.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/LogRoller.java index 42c03d8dd624..d28917c8a222 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/LogRoller.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/LogRoller.java @@ -32,6 +32,7 @@ import org.apache.hadoop.hbase.Server; import org.apache.hadoop.hbase.regionserver.wal.FSHLog; import org.apache.hadoop.hbase.regionserver.wal.FailedLogCloseException; +import org.apache.hadoop.hbase.util.EnvironmentEdgeManager; import org.apache.hadoop.hbase.wal.WAL; import org.apache.hadoop.hbase.regionserver.wal.WALActionsListener; import org.apache.hadoop.hbase.util.Bytes; @@ -148,7 +149,7 @@ void checkLowReplication(long now) { @Override public void run() { while (!server.isStopped()) { - long now = System.currentTimeMillis(); + long now = EnvironmentEdgeManager.currentTime(); checkLowReplication(now); if (!rollLog.get()) { boolean periodic = false; @@ -244,7 +245,7 @@ private void scheduleFlush(final byte [] encodedRegionName) { */ @VisibleForTesting public boolean walRollFinished() { - long now = System.currentTimeMillis(); + long now = EnvironmentEdgeManager.currentTime(); for (RollController controller : wals.values()) { if (controller.needsRoll(now)) { return false; @@ -266,7 +267,7 @@ protected class RollController { RollController(WAL wal) { this.wal = wal; this.rollRequest = new AtomicBoolean(false); - this.lastRollTime = System.currentTimeMillis(); + this.lastRollTime = EnvironmentEdgeManager.currentTime(); } public void requestRoll() { From 5f3e7f99da0798866d39adf2f19ac95c2c750826 Mon Sep 17 00:00:00 2001 From: wen_yi Date: Thu, 15 Oct 2020 13:59:11 +0800 Subject: [PATCH 08/10] fix findBugs warning --- .../java/org/apache/hadoop/hbase/regionserver/LogRoller.java | 1 + 1 file changed, 1 insertion(+) diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/LogRoller.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/LogRoller.java index d28917c8a222..1fa75fddb985 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/LogRoller.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/LogRoller.java @@ -67,6 +67,7 @@ public class LogRoller extends HasThread { // The interval to check low replication on hlog's pipeline private final long checkLowReplicationInterval; + @SuppressWarnings("unchecked") public void addWAL(final WAL wal) { if (null == wals.putIfAbsent(wal, new RollController(wal))) { wal.registerWALActionsListener(new WALActionsListener.Base() { From f05444091cdfa0419cd01887b130957411eb8f28 Mon Sep 17 00:00:00 2001 From: wen_yi Date: Thu, 15 Oct 2020 17:51:12 +0800 Subject: [PATCH 09/10] fix findBugs warning --- .../java/org/apache/hadoop/hbase/regionserver/LogRoller.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/LogRoller.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/LogRoller.java index 1fa75fddb985..301630ef6c01 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/LogRoller.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/LogRoller.java @@ -67,11 +67,13 @@ public class LogRoller extends HasThread { // The interval to check low replication on hlog's pipeline private final long checkLowReplicationInterval; - @SuppressWarnings("unchecked") public void addWAL(final WAL wal) { if (null == wals.putIfAbsent(wal, new RollController(wal))) { wal.registerWALActionsListener(new WALActionsListener.Base() { @Override + @edu.umd.cs.findbugs.annotations.SuppressWarnings( + value="JAT_OPERATION_SEQUENCE_ON_CONCURRENT_ABSTRACTION", + justification="Sequence of calls to concurrent abstraction may not be atomic") public void logRollRequested(WALActionsListener.RollRequestReason reason) { RollController controller = wals.get(wal); if (controller == null) { From ae452105ecf2b24524a54414a84e362adcf18943 Mon Sep 17 00:00:00 2001 From: wen_yi Date: Fri, 16 Oct 2020 16:39:37 +0800 Subject: [PATCH 10/10] fix findbugs warning --- .../apache/hadoop/hbase/regionserver/LogRoller.java | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/LogRoller.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/LogRoller.java index 301630ef6c01..08d5a335e325 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/LogRoller.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/LogRoller.java @@ -71,19 +71,11 @@ public void addWAL(final WAL wal) { if (null == wals.putIfAbsent(wal, new RollController(wal))) { wal.registerWALActionsListener(new WALActionsListener.Base() { @Override - @edu.umd.cs.findbugs.annotations.SuppressWarnings( - value="JAT_OPERATION_SEQUENCE_ON_CONCURRENT_ABSTRACTION", - justification="Sequence of calls to concurrent abstraction may not be atomic") public void logRollRequested(WALActionsListener.RollRequestReason reason) { RollController controller = wals.get(wal); if (controller == null) { - synchronized(wals) { - controller = wals.get(wal); - if (controller == null) { - controller = new RollController(wal); - wals.put(wal, controller); - } - } + wals.putIfAbsent(wal, new RollController(wal)); + controller = wals.get(wal); } controller.requestRoll(); // TODO logs will contend with each other here, replace with e.g. DelayedQueue