View Javadoc

1   /*
2    *
3    * Licensed to the Apache Software Foundation (ASF) under one
4    * or more contributor license agreements.  See the NOTICE file
5    * distributed with this work for additional information
6    * regarding copyright ownership.  The ASF licenses this file
7    * to you under the Apache License, Version 2.0 (the
8    * "License"); you may not use this file except in compliance
9    * with the License.  You may obtain a copy of the License at
10   *
11   *     http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing, software
14   * distributed under the License is distributed on an "AS IS" BASIS,
15   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   * See the License for the specific language governing permissions and
17   * limitations under the License.
18   */
19  
20  package org.apache.hadoop.hbase.client;
21  
22  import java.io.IOException;
23  import java.util.ArrayList;
24  import java.util.HashMap;
25  import java.util.List;
26  import java.util.Map;
27  import java.util.NavigableSet;
28  import java.util.TreeMap;
29  import java.util.TreeSet;
30  
31  import org.apache.commons.logging.Log;
32  import org.apache.commons.logging.LogFactory;
33  import org.apache.hadoop.classification.InterfaceAudience;
34  import org.apache.hadoop.classification.InterfaceStability;
35  import org.apache.hadoop.hbase.HConstants;
36  import org.apache.hadoop.hbase.filter.Filter;
37  import org.apache.hadoop.hbase.filter.IncompatibleFilterException;
38  import org.apache.hadoop.hbase.io.TimeRange;
39  import org.apache.hadoop.hbase.util.Bytes;
40  
41  /**
42   * Used to perform Scan operations.
43   * <p>
44   * All operations are identical to {@link Get} with the exception of
45   * instantiation.  Rather than specifying a single row, an optional startRow
46   * and stopRow may be defined.  If rows are not specified, the Scanner will
47   * iterate over all rows.
48   * <p>
49   * To scan everything for each row, instantiate a Scan object.
50   * <p>
51   * To modify scanner caching for just this scan, use {@link #setCaching(int) setCaching}.
52   * If caching is NOT set, we will use the caching value of the hosting {@link HTable}.  See
53   * {@link HTable#setScannerCaching(int)}. In addition to row caching, it is possible to specify a
54   * maximum result size, using {@link #setMaxResultSize(long)}. When both are used,
55   * single server requests are limited by either number of rows or maximum result size, whichever
56   * limit comes first.
57   * <p>
58   * To further define the scope of what to get when scanning, perform additional
59   * methods as outlined below.
60   * <p>
61   * To get all columns from specific families, execute {@link #addFamily(byte[]) addFamily}
62   * for each family to retrieve.
63   * <p>
64   * To get specific columns, execute {@link #addColumn(byte[], byte[]) addColumn}
65   * for each column to retrieve.
66   * <p>
67   * To only retrieve columns within a specific range of version timestamps,
68   * execute {@link #setTimeRange(long, long) setTimeRange}.
69   * <p>
70   * To only retrieve columns with a specific timestamp, execute
71   * {@link #setTimeStamp(long) setTimestamp}.
72   * <p>
73   * To limit the number of versions of each column to be returned, execute
74   * {@link #setMaxVersions(int) setMaxVersions}.
75   * <p>
76   * To limit the maximum number of values returned for each call to next(),
77   * execute {@link #setBatch(int) setBatch}.
78   * <p>
79   * To add a filter, execute {@link #setFilter(org.apache.hadoop.hbase.filter.Filter) setFilter}.
80   * <p>
81   * Expert: To explicitly disable server-side block caching for this scan,
82   * execute {@link #setCacheBlocks(boolean)}.
83   */
84  @InterfaceAudience.Public
85  @InterfaceStability.Stable
86  public class Scan extends Query {
87    private static final Log LOG = LogFactory.getLog(Scan.class);
88  
89    private static final String RAW_ATTR = "_raw_";
90    private static final String ISOLATION_LEVEL = "_isolationlevel_";
91  
92    /**
93     * EXPERT ONLY.
94     * An integer (not long) indicating to the scanner logic how many times we attempt to retrieve the
95     * next KV before we schedule a reseek.
96     * The right value depends on the size of the average KV. A reseek is more efficient when
97     * it can skip 5-10 KVs or 512B-1KB, or when the next KV is likely found in another HFile block.
98     * Setting this only has any effect when columns were added with
99     * {@link #addColumn(byte[], byte[])}
100    * <pre>{@code
101    * Scan s = new Scan(...);
102    * s.addColumn(...);
103    * s.setAttribute(Scan.HINT_LOOKAHEAD, Bytes.toBytes(2));
104    * }</pre>
105    * Default is 0 (always reseek).
106    */
107   public static final String HINT_LOOKAHEAD = "_look_ahead_";
108 
109   private byte [] startRow = HConstants.EMPTY_START_ROW;
110   private byte [] stopRow  = HConstants.EMPTY_END_ROW;
111   private int maxVersions = 1;
112   private int batch = -1;
113 
114   private int storeLimit = -1;
115   private int storeOffset = 0;
116   private boolean getScan;
117 
118   // If application wants to collect scan metrics, it needs to
119   // call scan.setAttribute(SCAN_ATTRIBUTES_ENABLE, Bytes.toBytes(Boolean.TRUE))
120   static public final String SCAN_ATTRIBUTES_METRICS_ENABLE = "scan.attributes.metrics.enable";
121   static public final String SCAN_ATTRIBUTES_METRICS_DATA = "scan.attributes.metrics.data";
122 
123   // If an application wants to use multiple scans over different tables each scan must
124   // define this attribute with the appropriate table name by calling
125   // scan.setAttribute(Scan.SCAN_ATTRIBUTES_TABLE_NAME, Bytes.toBytes(tableName))
126   static public final String SCAN_ATTRIBUTES_TABLE_NAME = "scan.attributes.table.name";
127 
128   /*
129    * -1 means no caching
130    */
131   private int caching = -1;
132   private long maxResultSize = -1;
133   private boolean cacheBlocks = true;
134   private boolean reversed = false;
135   private TimeRange tr = new TimeRange();
136   private Map<byte [], NavigableSet<byte []>> familyMap =
137     new TreeMap<byte [], NavigableSet<byte []>>(Bytes.BYTES_COMPARATOR);
138   private Boolean loadColumnFamiliesOnDemand = null;
139 
140   /**
141    * Set it true for small scan to get better performance
142    *
143    * Small scan should use pread and big scan can use seek + read
144    *
145    * seek + read is fast but can cause two problem (1) resource contention (2)
146    * cause too much network io
147    *
148    * [89-fb] Using pread for non-compaction read request
149    * https://issues.apache.org/jira/browse/HBASE-7266
150    *
151    * On the other hand, if setting it true, we would do
152    * openScanner,next,closeScanner in one RPC call. It means the better
153    * performance for small scan. [HBASE-9488].
154    *
155    * Generally, if the scan range is within one data block(64KB), it could be
156    * considered as a small scan.
157    */
158   private boolean small = false;
159 
160   /**
161    * Create a Scan operation across all rows.
162    */
163   public Scan() {}
164 
165   public Scan(byte [] startRow, Filter filter) {
166     this(startRow);
167     this.filter = filter;
168   }
169 
170   /**
171    * Create a Scan operation starting at the specified row.
172    * <p>
173    * If the specified row does not exist, the Scanner will start from the
174    * next closest row after the specified row.
175    * @param startRow row to start scanner at or after
176    */
177   public Scan(byte [] startRow) {
178     this.startRow = startRow;
179   }
180 
181   /**
182    * Create a Scan operation for the range of rows specified.
183    * @param startRow row to start scanner at or after (inclusive)
184    * @param stopRow row to stop scanner before (exclusive)
185    */
186   public Scan(byte [] startRow, byte [] stopRow) {
187     this.startRow = startRow;
188     this.stopRow = stopRow;
189     //if the startRow and stopRow both are empty, it is not a Get
190     this.getScan = isStartRowAndEqualsStopRow();
191   }
192 
193   /**
194    * Creates a new instance of this class while copying all values.
195    *
196    * @param scan  The scan instance to copy from.
197    * @throws IOException When copying the values fails.
198    */
199   public Scan(Scan scan) throws IOException {
200     startRow = scan.getStartRow();
201     stopRow  = scan.getStopRow();
202     maxVersions = scan.getMaxVersions();
203     batch = scan.getBatch();
204     storeLimit = scan.getMaxResultsPerColumnFamily();
205     storeOffset = scan.getRowOffsetPerColumnFamily();
206     caching = scan.getCaching();
207     maxResultSize = scan.getMaxResultSize();
208     cacheBlocks = scan.getCacheBlocks();
209     getScan = scan.isGetScan();
210     filter = scan.getFilter(); // clone?
211     loadColumnFamiliesOnDemand = scan.getLoadColumnFamiliesOnDemandValue();
212     consistency = scan.getConsistency();
213     reversed = scan.isReversed();
214     TimeRange ctr = scan.getTimeRange();
215     tr = new TimeRange(ctr.getMin(), ctr.getMax());
216     Map<byte[], NavigableSet<byte[]>> fams = scan.getFamilyMap();
217     for (Map.Entry<byte[],NavigableSet<byte[]>> entry : fams.entrySet()) {
218       byte [] fam = entry.getKey();
219       NavigableSet<byte[]> cols = entry.getValue();
220       if (cols != null && cols.size() > 0) {
221         for (byte[] col : cols) {
222           addColumn(fam, col);
223         }
224       } else {
225         addFamily(fam);
226       }
227     }
228     for (Map.Entry<String, byte[]> attr : scan.getAttributesMap().entrySet()) {
229       setAttribute(attr.getKey(), attr.getValue());
230     }
231   }
232 
233   /**
234    * Builds a scan object with the same specs as get.
235    * @param get get to model scan after
236    */
237   public Scan(Get get) {
238     this.startRow = get.getRow();
239     this.stopRow = get.getRow();
240     this.filter = get.getFilter();
241     this.cacheBlocks = get.getCacheBlocks();
242     this.maxVersions = get.getMaxVersions();
243     this.storeLimit = get.getMaxResultsPerColumnFamily();
244     this.storeOffset = get.getRowOffsetPerColumnFamily();
245     this.tr = get.getTimeRange();
246     this.familyMap = get.getFamilyMap();
247     this.getScan = true;
248     this.consistency = get.getConsistency();
249     for (Map.Entry<String, byte[]> attr : get.getAttributesMap().entrySet()) {
250       setAttribute(attr.getKey(), attr.getValue());
251     }
252   }
253 
254   public boolean isGetScan() {
255     return this.getScan || isStartRowAndEqualsStopRow();
256   }
257 
258   private boolean isStartRowAndEqualsStopRow() {
259     return this.startRow != null && this.startRow.length > 0 &&
260         Bytes.equals(this.startRow, this.stopRow);
261   }
262   /**
263    * Get all columns from the specified family.
264    * <p>
265    * Overrides previous calls to addColumn for this family.
266    * @param family family name
267    * @return this
268    */
269   public Scan addFamily(byte [] family) {
270     familyMap.remove(family);
271     familyMap.put(family, null);
272     return this;
273   }
274 
275   /**
276    * Get the column from the specified family with the specified qualifier.
277    * <p>
278    * Overrides previous calls to addFamily for this family.
279    * @param family family name
280    * @param qualifier column qualifier
281    * @return this
282    */
283   public Scan addColumn(byte [] family, byte [] qualifier) {
284     NavigableSet<byte []> set = familyMap.get(family);
285     if(set == null) {
286       set = new TreeSet<byte []>(Bytes.BYTES_COMPARATOR);
287     }
288     if (qualifier == null) {
289       qualifier = HConstants.EMPTY_BYTE_ARRAY;
290     }
291     set.add(qualifier);
292     familyMap.put(family, set);
293     return this;
294   }
295 
296   /**
297    * Get versions of columns only within the specified timestamp range,
298    * [minStamp, maxStamp).  Note, default maximum versions to return is 1.  If
299    * your time range spans more than one version and you want all versions
300    * returned, up the number of versions beyond the defaut.
301    * @param minStamp minimum timestamp value, inclusive
302    * @param maxStamp maximum timestamp value, exclusive
303    * @throws IOException if invalid time range
304    * @see #setMaxVersions()
305    * @see #setMaxVersions(int)
306    * @return this
307    */
308   public Scan setTimeRange(long minStamp, long maxStamp)
309   throws IOException {
310     tr = new TimeRange(minStamp, maxStamp);
311     return this;
312   }
313 
314   /**
315    * Get versions of columns with the specified timestamp. Note, default maximum
316    * versions to return is 1.  If your time range spans more than one version
317    * and you want all versions returned, up the number of versions beyond the
318    * defaut.
319    * @param timestamp version timestamp
320    * @see #setMaxVersions()
321    * @see #setMaxVersions(int)
322    * @return this
323    */
324   public Scan setTimeStamp(long timestamp)
325   throws IOException {
326     try {
327       tr = new TimeRange(timestamp, timestamp+1);
328     } catch(IOException e) {
329       // This should never happen, unless integer overflow or something extremely wrong...
330       LOG.error("TimeRange failed, likely caused by integer overflow. ", e);
331       throw e;
332     }
333     return this;
334   }
335 
336   /**
337    * Set the start row of the scan.
338    * @param startRow row to start scan on (inclusive)
339    * Note: In order to make startRow exclusive add a trailing 0 byte
340    * @return this
341    */
342   public Scan setStartRow(byte [] startRow) {
343     this.startRow = startRow;
344     return this;
345   }
346 
347   /**
348    * Set the stop row.
349    * @param stopRow row to end at (exclusive)
350    * Note: In order to make stopRow inclusive add a trailing 0 byte
351    * @return this
352    */
353   public Scan setStopRow(byte [] stopRow) {
354     this.stopRow = stopRow;
355     return this;
356   }
357 
358   /**
359    * Get all available versions.
360    * @return this
361    */
362   public Scan setMaxVersions() {
363     this.maxVersions = Integer.MAX_VALUE;
364     return this;
365   }
366 
367   /**
368    * Get up to the specified number of versions of each column.
369    * @param maxVersions maximum versions for each column
370    * @return this
371    */
372   public Scan setMaxVersions(int maxVersions) {
373     this.maxVersions = maxVersions;
374     return this;
375   }
376 
377   /**
378    * Set the maximum number of values to return for each call to next()
379    * @param batch the maximum number of values
380    */
381   public void setBatch(int batch) {
382     if (this.hasFilter() && this.filter.hasFilterRow()) {
383       throw new IncompatibleFilterException(
384         "Cannot set batch on a scan using a filter" +
385         " that returns true for filter.hasFilterRow");
386     }
387     this.batch = batch;
388   }
389 
390   /**
391    * Set the maximum number of values to return per row per Column Family
392    * @param limit the maximum number of values returned / row / CF
393    */
394   public void setMaxResultsPerColumnFamily(int limit) {
395     this.storeLimit = limit;
396   }
397 
398   /**
399    * Set offset for the row per Column Family.
400    * @param offset is the number of kvs that will be skipped.
401    */
402   public void setRowOffsetPerColumnFamily(int offset) {
403     this.storeOffset = offset;
404   }
405 
406   /**
407    * Set the number of rows for caching that will be passed to scanners.
408    * If not set, the default setting from {@link HTable#getScannerCaching()} will apply.
409    * Higher caching values will enable faster scanners but will use more memory.
410    * @param caching the number of rows for caching
411    */
412   public void setCaching(int caching) {
413     this.caching = caching;
414   }
415 
416   /**
417    * @return the maximum result size in bytes. See {@link #setMaxResultSize(long)}
418    */
419   public long getMaxResultSize() {
420     return maxResultSize;
421   }
422 
423   /**
424    * Set the maximum result size. The default is -1; this means that no specific
425    * maximum result size will be set for this scan, and the global configured
426    * value will be used instead. (Defaults to unlimited).
427    *
428    * @param maxResultSize The maximum result size in bytes.
429    */
430   public void setMaxResultSize(long maxResultSize) {
431     this.maxResultSize = maxResultSize;
432   }
433 
434   @Override
435   public Scan setFilter(Filter filter) {
436     super.setFilter(filter);
437     return this;
438   }
439 
440   /**
441    * Setting the familyMap
442    * @param familyMap map of family to qualifier
443    * @return this
444    */
445   public Scan setFamilyMap(Map<byte [], NavigableSet<byte []>> familyMap) {
446     this.familyMap = familyMap;
447     return this;
448   }
449 
450   /**
451    * Getting the familyMap
452    * @return familyMap
453    */
454   public Map<byte [], NavigableSet<byte []>> getFamilyMap() {
455     return this.familyMap;
456   }
457 
458   /**
459    * @return the number of families in familyMap
460    */
461   public int numFamilies() {
462     if(hasFamilies()) {
463       return this.familyMap.size();
464     }
465     return 0;
466   }
467 
468   /**
469    * @return true if familyMap is non empty, false otherwise
470    */
471   public boolean hasFamilies() {
472     return !this.familyMap.isEmpty();
473   }
474 
475   /**
476    * @return the keys of the familyMap
477    */
478   public byte[][] getFamilies() {
479     if(hasFamilies()) {
480       return this.familyMap.keySet().toArray(new byte[0][0]);
481     }
482     return null;
483   }
484 
485   /**
486    * @return the startrow
487    */
488   public byte [] getStartRow() {
489     return this.startRow;
490   }
491 
492   /**
493    * @return the stoprow
494    */
495   public byte [] getStopRow() {
496     return this.stopRow;
497   }
498 
499   /**
500    * @return the max number of versions to fetch
501    */
502   public int getMaxVersions() {
503     return this.maxVersions;
504   }
505 
506   /**
507    * @return maximum number of values to return for a single call to next()
508    */
509   public int getBatch() {
510     return this.batch;
511   }
512 
513   /**
514    * @return maximum number of values to return per row per CF
515    */
516   public int getMaxResultsPerColumnFamily() {
517     return this.storeLimit;
518   }
519 
520   /**
521    * Method for retrieving the scan's offset per row per column
522    * family (#kvs to be skipped)
523    * @return row offset
524    */
525   public int getRowOffsetPerColumnFamily() {
526     return this.storeOffset;
527   }
528 
529   /**
530    * @return caching the number of rows fetched when calling next on a scanner
531    */
532   public int getCaching() {
533     return this.caching;
534   }
535 
536   /**
537    * @return TimeRange
538    */
539   public TimeRange getTimeRange() {
540     return this.tr;
541   }
542 
543   /**
544    * @return RowFilter
545    */
546   @Override
547   public Filter getFilter() {
548     return filter;
549   }
550 
551   /**
552    * @return true is a filter has been specified, false if not
553    */
554   public boolean hasFilter() {
555     return filter != null;
556   }
557 
558   /**
559    * Set whether blocks should be cached for this Scan.
560    * <p>
561    * This is true by default.  When true, default settings of the table and
562    * family are used (this will never override caching blocks if the block
563    * cache is disabled for that family or entirely).
564    *
565    * @param cacheBlocks if false, default settings are overridden and blocks
566    * will not be cached
567    */
568   public void setCacheBlocks(boolean cacheBlocks) {
569     this.cacheBlocks = cacheBlocks;
570   }
571 
572   /**
573    * Get whether blocks should be cached for this Scan.
574    * @return true if default caching should be used, false if blocks should not
575    * be cached
576    */
577   public boolean getCacheBlocks() {
578     return cacheBlocks;
579   }
580 
581   /**
582    * Set whether this scan is a reversed one
583    * <p>
584    * This is false by default which means forward(normal) scan.
585    *
586    * @param reversed if true, scan will be backward order
587    * @return this
588    */
589   public Scan setReversed(boolean reversed) {
590     this.reversed = reversed;
591     return this;
592   }
593 
594   /**
595    * Get whether this scan is a reversed one.
596    * @return true if backward scan, false if forward(default) scan
597    */
598   public boolean isReversed() {
599     return reversed;
600   }
601 
602   /**
603    * Set the value indicating whether loading CFs on demand should be allowed (cluster
604    * default is false). On-demand CF loading doesn't load column families until necessary, e.g.
605    * if you filter on one column, the other column family data will be loaded only for the rows
606    * that are included in result, not all rows like in normal case.
607    * With column-specific filters, like SingleColumnValueFilter w/filterIfMissing == true,
608    * this can deliver huge perf gains when there's a cf with lots of data; however, it can
609    * also lead to some inconsistent results, as follows:
610    * - if someone does a concurrent update to both column families in question you may get a row
611    *   that never existed, e.g. for { rowKey = 5, { cat_videos => 1 }, { video => "my cat" } }
612    *   someone puts rowKey 5 with { cat_videos => 0 }, { video => "my dog" }, concurrent scan
613    *   filtering on "cat_videos == 1" can get { rowKey = 5, { cat_videos => 1 },
614    *   { video => "my dog" } }.
615    * - if there's a concurrent split and you have more than 2 column families, some rows may be
616    *   missing some column families.
617    */
618   public void setLoadColumnFamiliesOnDemand(boolean value) {
619     this.loadColumnFamiliesOnDemand = value;
620   }
621 
622   /**
623    * Get the raw loadColumnFamiliesOnDemand setting; if it's not set, can be null.
624    */
625   public Boolean getLoadColumnFamiliesOnDemandValue() {
626     return this.loadColumnFamiliesOnDemand;
627   }
628 
629   /**
630    * Get the logical value indicating whether on-demand CF loading should be allowed.
631    */
632   public boolean doLoadColumnFamiliesOnDemand() {
633     return (this.loadColumnFamiliesOnDemand != null)
634       && this.loadColumnFamiliesOnDemand.booleanValue();
635   }
636 
637   /**
638    * Compile the table and column family (i.e. schema) information
639    * into a String. Useful for parsing and aggregation by debugging,
640    * logging, and administration tools.
641    * @return Map
642    */
643   @Override
644   public Map<String, Object> getFingerprint() {
645     Map<String, Object> map = new HashMap<String, Object>();
646     List<String> families = new ArrayList<String>();
647     if(this.familyMap.size() == 0) {
648       map.put("families", "ALL");
649       return map;
650     } else {
651       map.put("families", families);
652     }
653     for (Map.Entry<byte [], NavigableSet<byte[]>> entry :
654         this.familyMap.entrySet()) {
655       families.add(Bytes.toStringBinary(entry.getKey()));
656     }
657     return map;
658   }
659 
660   /**
661    * Compile the details beyond the scope of getFingerprint (row, columns,
662    * timestamps, etc.) into a Map along with the fingerprinted information.
663    * Useful for debugging, logging, and administration tools.
664    * @param maxCols a limit on the number of columns output prior to truncation
665    * @return Map
666    */
667   @Override
668   public Map<String, Object> toMap(int maxCols) {
669     // start with the fingerpring map and build on top of it
670     Map<String, Object> map = getFingerprint();
671     // map from families to column list replaces fingerprint's list of families
672     Map<String, List<String>> familyColumns =
673       new HashMap<String, List<String>>();
674     map.put("families", familyColumns);
675     // add scalar information first
676     map.put("startRow", Bytes.toStringBinary(this.startRow));
677     map.put("stopRow", Bytes.toStringBinary(this.stopRow));
678     map.put("maxVersions", this.maxVersions);
679     map.put("batch", this.batch);
680     map.put("caching", this.caching);
681     map.put("maxResultSize", this.maxResultSize);
682     map.put("cacheBlocks", this.cacheBlocks);
683     map.put("loadColumnFamiliesOnDemand", this.loadColumnFamiliesOnDemand);
684     List<Long> timeRange = new ArrayList<Long>();
685     timeRange.add(this.tr.getMin());
686     timeRange.add(this.tr.getMax());
687     map.put("timeRange", timeRange);
688     int colCount = 0;
689     // iterate through affected families and list out up to maxCols columns
690     for (Map.Entry<byte [], NavigableSet<byte[]>> entry :
691       this.familyMap.entrySet()) {
692       List<String> columns = new ArrayList<String>();
693       familyColumns.put(Bytes.toStringBinary(entry.getKey()), columns);
694       if(entry.getValue() == null) {
695         colCount++;
696         --maxCols;
697         columns.add("ALL");
698       } else {
699         colCount += entry.getValue().size();
700         if (maxCols <= 0) {
701           continue;
702         }
703         for (byte [] column : entry.getValue()) {
704           if (--maxCols <= 0) {
705             continue;
706           }
707           columns.add(Bytes.toStringBinary(column));
708         }
709       }
710     }
711     map.put("totalColumns", colCount);
712     if (this.filter != null) {
713       map.put("filter", this.filter.toString());
714     }
715     // add the id if set
716     if (getId() != null) {
717       map.put("id", getId());
718     }
719     return map;
720   }
721 
722   /**
723    * Enable/disable "raw" mode for this scan.
724    * If "raw" is enabled the scan will return all
725    * delete marker and deleted rows that have not
726    * been collected, yet.
727    * This is mostly useful for Scan on column families
728    * that have KEEP_DELETED_ROWS enabled.
729    * It is an error to specify any column when "raw" is set.
730    * @param raw True/False to enable/disable "raw" mode.
731    */
732   public void setRaw(boolean raw) {
733     setAttribute(RAW_ATTR, Bytes.toBytes(raw));
734   }
735 
736   /**
737    * @return True if this Scan is in "raw" mode.
738    */
739   public boolean isRaw() {
740     byte[] attr = getAttribute(RAW_ATTR);
741     return attr == null ? false : Bytes.toBoolean(attr);
742   }
743 
744   /*
745    * Set the isolation level for this scan. If the
746    * isolation level is set to READ_UNCOMMITTED, then
747    * this scan will return data from committed and
748    * uncommitted transactions. If the isolation level
749    * is set to READ_COMMITTED, then this scan will return
750    * data from committed transactions only. If a isolation
751    * level is not explicitly set on a Scan, then it
752    * is assumed to be READ_COMMITTED.
753    * @param level IsolationLevel for this scan
754    */
755   public void setIsolationLevel(IsolationLevel level) {
756     setAttribute(ISOLATION_LEVEL, level.toBytes());
757   }
758   /*
759    * @return The isolation level of this scan.
760    * If no isolation level was set for this scan object,
761    * then it returns READ_COMMITTED.
762    * @return The IsolationLevel for this scan
763    */
764   public IsolationLevel getIsolationLevel() {
765     byte[] attr = getAttribute(ISOLATION_LEVEL);
766     return attr == null ? IsolationLevel.READ_COMMITTED :
767                           IsolationLevel.fromBytes(attr);
768   }
769 
770   /**
771    * Set whether this scan is a small scan
772    * <p>
773    * Small scan should use pread and big scan can use seek + read
774    *
775    * seek + read is fast but can cause two problem (1) resource contention (2)
776    * cause too much network io
777    *
778    * [89-fb] Using pread for non-compaction read request
779    * https://issues.apache.org/jira/browse/HBASE-7266
780    *
781    * On the other hand, if setting it true, we would do
782    * openScanner,next,closeScanner in one RPC call. It means the better
783    * performance for small scan. [HBASE-9488].
784    *
785    * Generally, if the scan range is within one data block(64KB), it could be
786    * considered as a small scan.
787    *
788    * @param small
789    */
790   public void setSmall(boolean small) {
791     this.small = small;
792   }
793 
794   /**
795    * Get whether this scan is a small scan
796    * @return true if small scan
797    */
798   public boolean isSmall() {
799     return small;
800   }
801 }