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 */
018
019package org.apache.hadoop.hbase.regionserver;
020
021import org.apache.yetus.audience.InterfaceAudience;
022import org.apache.hadoop.conf.Configuration;
023import org.apache.hadoop.hbase.CellComparator;
024import org.apache.hadoop.hbase.client.ColumnFamilyDescriptor;
025import org.apache.hadoop.hbase.HConstants;
026import org.apache.hadoop.hbase.KeepDeletedCells;
027import org.apache.hadoop.hbase.util.Bytes;
028import org.apache.hadoop.hbase.util.ClassSize;
029
030import org.apache.hbase.thirdparty.com.google.common.annotations.VisibleForTesting;
031
032/**
033 * Immutable information for scans over a store.
034 */
035// Has to be public for PartitionedMobCompactor to access; ditto on tests making use of a few of
036// the accessors below. Shutdown access. TODO
037@VisibleForTesting
038@InterfaceAudience.Private
039public class ScanInfo {
040  private byte[] family;
041  private int minVersions;
042  private int maxVersions;
043  private long ttl;
044  private KeepDeletedCells keepDeletedCells;
045  private long timeToPurgeDeletes;
046  private CellComparator comparator;
047  private long tableMaxRowSize;
048  private boolean usePread;
049  private long cellsPerTimeoutCheck;
050  private boolean parallelSeekEnabled;
051  private final long preadMaxBytes;
052  private final boolean newVersionBehavior;
053
054  public static final long FIXED_OVERHEAD = ClassSize.align(ClassSize.OBJECT
055      + (2 * ClassSize.REFERENCE) + (2 * Bytes.SIZEOF_INT)
056      + (4 * Bytes.SIZEOF_LONG) + (4 * Bytes.SIZEOF_BOOLEAN));
057
058  /**
059   * @param conf
060   * @param family {@link ColumnFamilyDescriptor} describing the column family
061   * @param ttl Store's TTL (in ms)
062   * @param timeToPurgeDeletes duration in ms after which a delete marker can be purged during a
063   *          major compaction.
064   * @param comparator The store's comparator
065   */
066  public ScanInfo(Configuration conf, ColumnFamilyDescriptor family, long ttl,
067      long timeToPurgeDeletes, CellComparator comparator) {
068    this(conf, family.getName(), family.getMinVersions(), family.getMaxVersions(), ttl,
069        family.getKeepDeletedCells(), family.getBlocksize(), timeToPurgeDeletes, comparator,
070        family.isNewVersionBehavior());
071  }
072
073  private static long getCellsPerTimeoutCheck(Configuration conf) {
074    long perHeartbeat = conf.getLong(StoreScanner.HBASE_CELLS_SCANNED_PER_HEARTBEAT_CHECK,
075      StoreScanner.DEFAULT_HBASE_CELLS_SCANNED_PER_HEARTBEAT_CHECK);
076    return perHeartbeat > 0 ? perHeartbeat
077        : StoreScanner.DEFAULT_HBASE_CELLS_SCANNED_PER_HEARTBEAT_CHECK;
078  }
079
080  /**
081   * @param conf
082   * @param family Name of this store's column family
083   * @param minVersions Store's MIN_VERSIONS setting
084   * @param maxVersions Store's VERSIONS setting
085   * @param ttl Store's TTL (in ms)
086   * @param blockSize Store's block size
087   * @param timeToPurgeDeletes duration in ms after which a delete marker can
088   *        be purged during a major compaction.
089   * @param keepDeletedCells Store's keepDeletedCells setting
090   * @param comparator The store's comparator
091   */
092  public ScanInfo(Configuration conf, byte[] family, int minVersions, int maxVersions, long ttl,
093      KeepDeletedCells keepDeletedCells, long blockSize, long timeToPurgeDeletes,
094      CellComparator comparator, boolean newVersionBehavior) {
095    this(family, minVersions, maxVersions, ttl, keepDeletedCells, timeToPurgeDeletes, comparator,
096        conf.getLong(HConstants.TABLE_MAX_ROWSIZE_KEY, HConstants.TABLE_MAX_ROWSIZE_DEFAULT),
097        conf.getBoolean("hbase.storescanner.use.pread", false), getCellsPerTimeoutCheck(conf),
098        conf.getBoolean(StoreScanner.STORESCANNER_PARALLEL_SEEK_ENABLE, false),
099        conf.getLong(StoreScanner.STORESCANNER_PREAD_MAX_BYTES, 4 * blockSize), newVersionBehavior);
100  }
101
102  private ScanInfo(byte[] family, int minVersions, int maxVersions, long ttl,
103      KeepDeletedCells keepDeletedCells, long timeToPurgeDeletes, CellComparator comparator,
104      long tableMaxRowSize, boolean usePread, long cellsPerTimeoutCheck,
105      boolean parallelSeekEnabled, long preadMaxBytes, boolean newVersionBehavior) {
106    this.family = family;
107    this.minVersions = minVersions;
108    this.maxVersions = maxVersions;
109    this.ttl = ttl;
110    this.keepDeletedCells = keepDeletedCells;
111    this.timeToPurgeDeletes = timeToPurgeDeletes;
112    this.comparator = comparator;
113    this.tableMaxRowSize = tableMaxRowSize;
114    this.usePread = usePread;
115    this.cellsPerTimeoutCheck = cellsPerTimeoutCheck;
116    this.parallelSeekEnabled = parallelSeekEnabled;
117    this.preadMaxBytes = preadMaxBytes;
118    this.newVersionBehavior = newVersionBehavior;
119  }
120
121  long getTableMaxRowSize() {
122    return this.tableMaxRowSize;
123  }
124
125  boolean isUsePread() {
126    return this.usePread;
127  }
128
129  long getCellsPerTimeoutCheck() {
130    return this.cellsPerTimeoutCheck;
131  }
132
133  boolean isParallelSeekEnabled() {
134    return this.parallelSeekEnabled;
135  }
136
137  public byte[] getFamily() {
138    return family;
139  }
140
141  public int getMinVersions() {
142    return minVersions;
143  }
144
145  public int getMaxVersions() {
146    return maxVersions;
147  }
148
149  public long getTtl() {
150    return ttl;
151  }
152
153  public KeepDeletedCells getKeepDeletedCells() {
154    return keepDeletedCells;
155  }
156
157  public long getTimeToPurgeDeletes() {
158    return timeToPurgeDeletes;
159  }
160
161  public CellComparator getComparator() {
162    return comparator;
163  }
164
165  long getPreadMaxBytes() {
166    return preadMaxBytes;
167  }
168
169  public boolean isNewVersionBehavior() {
170    return newVersionBehavior;
171  }
172
173  /**
174   * Used for CP users for customizing max versions, ttl and keepDeletedCells.
175   */
176  ScanInfo customize(int maxVersions, long ttl, KeepDeletedCells keepDeletedCells) {
177    return new ScanInfo(family, minVersions, maxVersions, ttl, keepDeletedCells, timeToPurgeDeletes,
178        comparator, tableMaxRowSize, usePread, cellsPerTimeoutCheck, parallelSeekEnabled,
179        preadMaxBytes, newVersionBehavior);
180  }
181}