@Override
    protected boolean swapPipelineWithNull(VersionedSegmentsList segments) {
      if (Thread.currentThread().getName().equals(TAKE_SNAPSHOT_THREAD_NAME)) {
        int currentCount = swapPipelineWithNullCounter.incrementAndGet();
        if (currentCount <= 1) {
          try {
            flattenOneSegmentPostCyclicBarrier.await();
          } catch (Throwable e) {
            throw new RuntimeException(e);
          }
        }

        if (currentCount == 2) {
          try {
            /**
             * Only the snapshot thread retry {@link CompactingMemStore#swapPipelineWithNull},
             * writeAgain thread could start.
             */
            writeMemStoreAgainStartCyclicBarrier.await();
            /**
             * Only the writeAgain thread completes, retry
             * {@link CompactingMemStore#swapPipelineWithNull} would execute.
             */
            writeMemStoreAgainEndCyclicBarrier.await();
          } catch (Throwable e) {
            throw new RuntimeException(e);
          }
        }

      }
      boolean result = super.swapPipelineWithNull(segments);
      if (Thread.currentThread().getName().equals(TAKE_SNAPSHOT_THREAD_NAME)) {
        int currentCount = swapPipelineWithNullCounter.get();
        if (currentCount <= 1) {
          assertTrue(!result);
        }
        if (currentCount == 2) {
          assertTrue(result);
        }
      }
      return result;

    }
This is used for snapshot thread,writeAgain thread and in memory compact thread. Only the
writeAgain thread completes, {@link CompactingMemStore#swapPipelineWithNull} would
execute,and in memory compact thread would exit,because we expect that in memory compact
executing only once.
hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestHStore.java