@Override
  public MemStoreSnapshot snapshot() {
    // If snapshot currently has entries, then flusher failed or didn't call
    // cleanup. Log a warning.
    if (!this.snapshot.isEmpty()) {
      LOG.warn("Snapshot called again without clearing previous. "
        + "Doing nothing. Another ongoing flush or did we fail last attempt?");
    } else {
      this.snapshotId = EnvironmentEdgeManager.currentTime();
      if (!getActive().isEmpty()) {
        // Record the ImmutableSegment' heap overhead when initialing
        MemStoreSizing memstoreAccounting = new NonThreadSafeMemStoreSizing();
        ImmutableSegment immutableSegment =
          SegmentFactory.instance().createImmutableSegment(getActive(), memstoreAccounting);
        // regionServices can be null when testing
        if (regionServices != null) {
          regionServices.addMemStoreSize(memstoreAccounting.getDataSize(),
            memstoreAccounting.getHeapSize(), memstoreAccounting.getOffHeapSize(),
            memstoreAccounting.getCellsCount());
        }
        this.snapshot = immutableSegment;
        resetActive();
        resetTimeOfOldestEdit();
      }
    }
    return new MemStoreSnapshot(this.snapshotId, this.snapshot);
  }
Creates a snapshot of the current memstore. Snapshot must be cleared by call to
{@link #clearSnapshot(long)}
hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/DefaultMemStore.java