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