@Override
    protected void doClearSnapShot() {
      if (Thread.currentThread().getName().equals(FLUSH_THREAD_NAME)) {
        int currentCount = clearSnapshotCounter.incrementAndGet();
        if (currentCount == 1) {
          try {
            if (
              ((ReentrantReadWriteLock) store.getStoreEngine().getLock())
                .isWriteLockedByCurrentThread()
            ) {
              shouldWait = false;
            }
            /**
             * Only when flush thread enters {@link DefaultMemStore#doClearSnapShot}, getScanner
             * thread could start.
             */
            getScannerCyclicBarrier.await();

            if (shouldWait) {
              /**
               * Wait for {@link DefaultMemStore#getSnapshotSegments} completed.
               */
              preClearSnapShotCyclicBarrier.await();
            }
          } catch (Throwable e) {
            throw new RuntimeException(e);
          }
        }
      }
      super.doClearSnapShot();

      if (Thread.currentThread().getName().equals(FLUSH_THREAD_NAME)) {
        int currentCount = clearSnapshotCounter.get();
        if (currentCount == 1) {
          if (shouldWait) {
            try {
              /**
               * Notify getScanner thread {@link DefaultMemStore#doClearSnapShot} completed,
               * {@link DefaultMemStore#getScanners} could continue.
               */
              postClearSnapShotCyclicBarrier.await();
            } catch (Throwable e) {
              throw new RuntimeException(e);
            }
          }
        }
      }
    }
Wait for {@link DefaultMemStore#doClearSnapShot} completed.
hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestHStore.java