@Override
    public VersionedSegmentsList getImmutableSegments() {
      VersionedSegmentsList result = super.getImmutableSegments();
      if (Thread.currentThread().getName().equals(TAKE_SNAPSHOT_THREAD_NAME)) {
        int currentCount = getImmutableSegmentsListCounter.incrementAndGet();
        if (currentCount <= 1) {
          try {
            flattenOneSegmentPreCyclicBarrier.await();
          } catch (Throwable e) {
            throw new RuntimeException(e);
          }
        }

      }

      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