HBASE-26412 Handle sink failure in RegionReplicationSink (#3815)
[hbase.git] / hbase-server / src / main / java / org / apache / hadoop / hbase / regionserver / SnapshotSegmentScanner.java
blob87be2e4031dbe1a5e318ec7021a526137417e143
1 /*
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;
27 /**
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;
38 private Cell current;
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();
53 @Override
54 public Cell peek() {
55 return current;
58 @Override
59 public Cell next() {
60 Cell oldCurrent = current;
61 if(iter.hasNext()){
62 current = iter.next();
63 } else {
64 current = null;
66 return oldCurrent;
69 @Override
70 public boolean seek(Cell seekCell) {
71 // restart iterator
72 this.iter = createIterator(this.segment);
73 return reseek(seekCell);
76 @Override
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);
81 if (ret >= 0) {
82 this.current = next;
83 return true;
86 return false;
89 /**
90 * @see KeyValueScanner#getScannerOrder()
92 @Override
93 public long getScannerOrder() {
94 return 0;
97 @Override
98 public void close() {
99 this.segment.decScannerCount();