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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 package org
.apache
.hadoop
.hbase
.regionserver
;
21 import java
.util
.Iterator
;
23 import org
.apache
.hadoop
.hbase
.Cell
;
24 import org
.apache
.yetus
.audience
.InterfaceAudience
;
28 * A basic SegmentScanner used against an ImmutableScanner snapshot
29 * Used flushing where we do a single pass, no reverse scanning or
30 * inserts happening. Its a dumbed-down Scanner that can go fast.
31 * Like {@link org.apache.hadoop.hbase.util.CollectionBackedScanner}
32 * (but making it know about Segments was onerous).
34 @InterfaceAudience.Private
35 public class SnapshotSegmentScanner
extends NonReversedNonLazyKeyValueScanner
{
36 private final ImmutableSegment segment
;
37 private Iterator
<Cell
> iter
;
40 public SnapshotSegmentScanner(ImmutableSegment segment
) {
41 this.segment
= segment
;
42 this.segment
.incScannerCount();
43 this.iter
= createIterator(this.segment
);
44 if (this.iter
.hasNext()){
45 this.current
= this.iter
.next();
49 private static Iterator
<Cell
> createIterator(Segment segment
) {
50 return segment
.getCellSet().iterator();
60 Cell oldCurrent
= current
;
62 current
= iter
.next();
70 public boolean seek(Cell seekCell
) {
72 this.iter
= createIterator(this.segment
);
73 return reseek(seekCell
);
77 public boolean reseek(Cell seekCell
) {
78 while (this.iter
.hasNext()){
79 Cell next
= this.iter
.next();
80 int ret
= this.segment
.getComparator().compare(next
, seekCell
);
90 * @see KeyValueScanner#getScannerOrder()
93 public long getScannerOrder() {
99 this.segment
.decScannerCount();