001/**
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *     http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018package org.apache.hadoop.hbase.regionserver;
019
020import org.apache.yetus.audience.InterfaceAudience;
021
022import java.io.Closeable;
023import java.util.List;
024/**
025 * Holds details of the snapshot taken on a MemStore. Details include the snapshot's identifier,
026 * count of cells in it and total memory size occupied by all the cells, timestamp information of
027 * all the cells and a scanner to read all cells in it.
028 */
029@InterfaceAudience.Private
030public class MemStoreSnapshot implements Closeable {
031  private final long id;
032  private final int cellsCount;
033  private final MemStoreSize memStoreSize;
034  private final TimeRangeTracker timeRangeTracker;
035  private final List<KeyValueScanner> scanners;
036  private final boolean tagsPresent;
037
038  public MemStoreSnapshot(long id, ImmutableSegment snapshot) {
039    this.id = id;
040    this.cellsCount = snapshot.getCellsCount();
041    this.memStoreSize = snapshot.getMemStoreSize();
042    this.timeRangeTracker = snapshot.getTimeRangeTracker();
043    this.scanners = snapshot.getSnapshotScanners();
044    this.tagsPresent = snapshot.isTagsPresent();
045  }
046
047  /**
048   * @return snapshot's identifier.
049   */
050  public long getId() {
051    return id;
052  }
053
054  /**
055   * @return Number of Cells in this snapshot.
056   */
057  public int getCellsCount() {
058    return cellsCount;
059  }
060
061  public long getDataSize() {
062    return memStoreSize.getDataSize();
063  }
064
065  public MemStoreSize getMemStoreSize() {
066    return memStoreSize;
067  }
068
069  /**
070   * @return {@link TimeRangeTracker} for all the Cells in the snapshot.
071   */
072  public TimeRangeTracker getTimeRangeTracker() {
073    return timeRangeTracker;
074  }
075
076  /**
077   * @return {@link KeyValueScanner} for iterating over the snapshot
078   */
079  public List<KeyValueScanner> getScanners() {
080    return scanners;
081  }
082
083  /**
084   * @return true if tags are present in this snapshot
085   */
086  public boolean isTagsPresent() {
087    return this.tagsPresent;
088  }
089
090  @Override
091  public void close() {
092    if (this.scanners != null) {
093      for (KeyValueScanner scanner : scanners) {
094        scanner.close();
095      }
096    }
097  }
098}