Skip to content

Commit da27a67

Browse files
authored
HBASE-27152 Under compaction mark may leak (#4568)
Signed-off-by: Duo Zhang <[email protected]>
1 parent 075b305 commit da27a67

File tree

1 file changed

+10
-22
lines changed

1 file changed

+10
-22
lines changed

hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/CompactSplit.java

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
import java.util.concurrent.ConcurrentHashMap;
3232
import java.util.concurrent.Executors;
3333
import java.util.concurrent.RejectedExecutionException;
34-
import java.util.concurrent.RejectedExecutionHandler;
3534
import java.util.concurrent.ThreadPoolExecutor;
3635
import java.util.concurrent.TimeUnit;
3736
import java.util.concurrent.atomic.AtomicInteger;
@@ -145,15 +144,15 @@ private void createCompactionExecutors() {
145144
final String n = Thread.currentThread().getName();
146145

147146
StealJobQueue<Runnable> stealJobQueue = new StealJobQueue<Runnable>(COMPARATOR);
147+
// Since the StealJobQueue is unbounded, we need not to set the RejectedExecutionHandler for
148+
// the long and short compaction thread pool executors.
148149
this.longCompactions = new ThreadPoolExecutor(largeThreads, largeThreads, 60, TimeUnit.SECONDS,
149150
stealJobQueue,
150151
new ThreadFactoryBuilder().setNameFormat(n + "-longCompactions-%d").setDaemon(true).build());
151-
this.longCompactions.setRejectedExecutionHandler(new Rejection());
152152
this.longCompactions.prestartAllCoreThreads();
153153
this.shortCompactions = new ThreadPoolExecutor(smallThreads, smallThreads, 60, TimeUnit.SECONDS,
154154
stealJobQueue.getStealFromQueue(),
155155
new ThreadFactoryBuilder().setNameFormat(n + "-shortCompactions-%d").setDaemon(true).build());
156-
this.shortCompactions.setRejectedExecutionHandler(new Rejection());
157156
}
158157

159158
@Override
@@ -382,15 +381,20 @@ protected void requestCompactionInternal(HRegion region, HStore store, String wh
382381
// pool; we will do selection there, and move to large pool if necessary.
383382
pool = shortCompactions;
384383
}
385-
pool.execute(
386-
new CompactionRunner(store, region, compaction, tracker, completeTracker, pool, user));
384+
385+
// A simple implementation for under compaction marks.
386+
// Since this method is always called in the synchronized methods, we do not need to use the
387+
// boolean result to make sure that exactly the one that added here will be removed
388+
// in the next steps.
389+
underCompactionStores.add(getStoreNameForUnderCompaction(store));
387390
if (LOG.isDebugEnabled()) {
388391
LOG.debug(
389392
"Add compact mark for store {}, priority={}, current under compaction "
390393
+ "store size is {}",
391394
getStoreNameForUnderCompaction(store), priority, underCompactionStores.size());
392395
}
393-
underCompactionStores.add(getStoreNameForUnderCompaction(store));
396+
pool.submit(
397+
new CompactionRunner(store, region, compaction, tracker, completeTracker, pool, user));
394398
region.incrementCompactionsQueuedCount();
395399
if (LOG.isDebugEnabled()) {
396400
String type = (pool == shortCompactions) ? "Small " : "Large ";
@@ -719,22 +723,6 @@ private String formatStackTrace(Exception ex) {
719723
}
720724
}
721725

722-
/**
723-
* Cleanup class to use when rejecting a compaction request from the queue.
724-
*/
725-
private static class Rejection implements RejectedExecutionHandler {
726-
@Override
727-
public void rejectedExecution(Runnable runnable, ThreadPoolExecutor pool) {
728-
if (runnable instanceof CompactionRunner) {
729-
CompactionRunner runner = (CompactionRunner) runnable;
730-
LOG.debug("Compaction Rejected: " + runner);
731-
if (runner.compaction != null) {
732-
runner.store.cancelRequestedCompaction(runner.compaction);
733-
}
734-
}
735-
}
736-
}
737-
738726
/**
739727
* {@inheritDoc}
740728
*/

0 commit comments

Comments
 (0)