HBASE-16162 Compacting Memstore : unnecessary push of active segments to pipeline.

This commit is contained in:
anoopsjohn 2016-07-06 18:54:35 +05:30
parent ae92668dd6
commit 581d2b7de5
2 changed files with 35 additions and 30 deletions

View File

@ -67,7 +67,6 @@ public class CompactingMemStore extends AbstractMemStore {
// the threshold on active size for in-memory flush // the threshold on active size for in-memory flush
private long inmemoryFlushSize; private long inmemoryFlushSize;
private final AtomicBoolean inMemoryFlushInProgress = new AtomicBoolean(false); private final AtomicBoolean inMemoryFlushInProgress = new AtomicBoolean(false);
@VisibleForTesting
private final AtomicBoolean allowCompaction = new AtomicBoolean(true); private final AtomicBoolean allowCompaction = new AtomicBoolean(true);
public CompactingMemStore(Configuration conf, CellComparator c, public CompactingMemStore(Configuration conf, CellComparator c,
@ -199,10 +198,6 @@ public class CompactingMemStore extends AbstractMemStore {
return list; return list;
} }
public void setInMemoryFlushInProgress(boolean inMemoryFlushInProgress) {
this.inMemoryFlushInProgress.set(inMemoryFlushInProgress);
}
public boolean swapCompactedSegments(VersionedSegmentsList versionedList, public boolean swapCompactedSegments(VersionedSegmentsList versionedList,
ImmutableSegment result) { ImmutableSegment result) {
return pipeline.swap(versionedList, result); return pipeline.swap(versionedList, result);
@ -275,31 +270,38 @@ public class CompactingMemStore extends AbstractMemStore {
// otherwise there is a deadlock // otherwise there is a deadlock
@VisibleForTesting @VisibleForTesting
void flushInMemory() throws IOException { void flushInMemory() throws IOException {
// Phase I: Update the pipeline // setting the inMemoryFlushInProgress flag again for the case this method is invoked
getRegionServices().blockUpdates(); // directly (only in tests) in the common path setting from true to true is idempotent
// Speculative compaction execution, may be interrupted if flush is forced while
// compaction is in progress
inMemoryFlushInProgress.set(true);
try { try {
MutableSegment active = getActive(); // Phase I: Update the pipeline
if (LOG.isDebugEnabled()) { getRegionServices().blockUpdates();
LOG.debug("IN-MEMORY FLUSH: Pushing active segment into compaction pipeline, " try {
+ "and initiating compaction."); MutableSegment active = getActive();
if (LOG.isDebugEnabled()) {
LOG.debug("IN-MEMORY FLUSH: Pushing active segment into compaction pipeline, "
+ "and initiating compaction.");
}
pushActiveToPipeline(active);
} finally {
getRegionServices().unblockUpdates();
} }
pushActiveToPipeline(active); // Used by tests
} finally { if (!allowCompaction.get()) {
getRegionServices().unblockUpdates(); return;
} }
// Phase II: Compact the pipeline // Phase II: Compact the pipeline
try { try {
if (allowCompaction.get() && inMemoryFlushInProgress.compareAndSet(false, true)) {
// setting the inMemoryFlushInProgress flag again for the case this method is invoked
// directly (only in tests) in the common path setting from true to true is idempotent
// Speculative compaction execution, may be interrupted if flush is forced while
// compaction is in progress
compactor.startCompaction(); compactor.startCompaction();
} catch (IOException e) {
LOG.warn("Unable to run memstore compaction. region "
+ getRegionServices().getRegionInfo().getRegionNameAsString() + "store: "
+ getFamilyName(), e);
} }
} catch (IOException e) { } finally {
LOG.warn("Unable to run memstore compaction. region " inMemoryFlushInProgress.set(false);
+ getRegionServices().getRegionInfo().getRegionNameAsString()
+ "store: "+ getFamilyName(), e);
} }
} }
@ -312,9 +314,9 @@ public class CompactingMemStore extends AbstractMemStore {
} }
private boolean shouldFlushInMemory() { private boolean shouldFlushInMemory() {
if(getActive().getSize() > inmemoryFlushSize) { if (getActive().getSize() > inmemoryFlushSize) {
// size above flush threshold // size above flush threshold
return (allowCompaction.get() && !inMemoryFlushInProgress.get()); return inMemoryFlushInProgress.compareAndSet(false, true);
} }
return false; return false;
} }
@ -361,7 +363,8 @@ public class CompactingMemStore extends AbstractMemStore {
*/ */
private class InMemoryFlushRunnable implements Runnable { private class InMemoryFlushRunnable implements Runnable {
@Override public void run() { @Override
public void run() {
try { try {
flushInMemory(); flushInMemory();
} catch (IOException e) { } catch (IOException e) {
@ -375,14 +378,17 @@ public class CompactingMemStore extends AbstractMemStore {
//---------------------------------------------------------------------- //----------------------------------------------------------------------
//methods for tests //methods for tests
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@VisibleForTesting
boolean isMemStoreFlushingInMemory() { boolean isMemStoreFlushingInMemory() {
return inMemoryFlushInProgress.get(); return inMemoryFlushInProgress.get();
} }
@VisibleForTesting
void disableCompaction() { void disableCompaction() {
allowCompaction.set(false); allowCompaction.set(false);
} }
@VisibleForTesting
void enableCompaction() { void enableCompaction() {
allowCompaction.set(true); allowCompaction.set(true);
} }

View File

@ -153,7 +153,6 @@ class MemStoreCompactor {
return; return;
} finally { } finally {
releaseResources(); releaseResources();
compactingMemStore.setInMemoryFlushInProgress(false);
} }
} }