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