HBASE-26286: Add support for specifying store file tracker when restoring or cloning...
[hbase.git] / hbase-server / src / main / java / org / apache / hadoop / hbase / regionserver / CellSet.java
blobe1cfd15ed1956944bae05b76831c5d0123a945e9
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.Collection;
22 import java.util.Comparator;
23 import java.util.Iterator;
24 import java.util.NavigableSet;
25 import java.util.NavigableMap;
26 import java.util.SortedSet;
27 import java.util.concurrent.ConcurrentSkipListMap;
29 import org.apache.hadoop.hbase.Cell;
30 import org.apache.hadoop.hbase.CellComparator;
31 import org.apache.hadoop.hbase.HConstants;
32 import org.apache.yetus.audience.InterfaceAudience;
34 /**
35 * A {@link java.util.Set} of {@link Cell}s, where an add will overwrite the entry if already
36 * exists in the set. The call to add returns true if no value in the backing map or false if
37 * there was an entry with same key (though value may be different).
38 * implementation is tolerant of concurrent get and set and won't throw
39 * ConcurrentModificationException when iterating.
41 @InterfaceAudience.Private
42 public class CellSet implements NavigableSet<Cell> {
44 public static final int UNKNOWN_NUM_UNIQUES = -1;
45 // Implemented on top of a {@link java.util.concurrent.ConcurrentSkipListMap}
46 // Differ from CSLS in one respect, where CSLS does "Adds the specified element to this set if it
47 // is not already present.", this implementation "Adds the specified element to this set EVEN
48 // if it is already present overwriting what was there previous".
49 // Otherwise, has same attributes as ConcurrentSkipListSet
50 private final NavigableMap<Cell, Cell> delegatee; ///
52 private final int numUniqueKeys;
54 public CellSet(final CellComparator c) {
55 this.delegatee = new ConcurrentSkipListMap<>(c.getSimpleComparator());
56 this.numUniqueKeys = UNKNOWN_NUM_UNIQUES;
59 CellSet(final NavigableMap<Cell, Cell> m, int numUniqueKeys) {
60 this.delegatee = m;
61 this.numUniqueKeys = numUniqueKeys;
64 CellSet(final NavigableMap<Cell, Cell> m) {
65 this.delegatee = m;
66 this.numUniqueKeys = UNKNOWN_NUM_UNIQUES;
69 NavigableMap<Cell, Cell> getDelegatee() {
70 return delegatee;
73 @Override
74 public Cell ceiling(Cell e) {
75 throw new UnsupportedOperationException(HConstants.NOT_IMPLEMENTED);
78 @Override
79 public Iterator<Cell> descendingIterator() {
80 return this.delegatee.descendingMap().values().iterator();
83 @Override
84 public NavigableSet<Cell> descendingSet() {
85 throw new UnsupportedOperationException(HConstants.NOT_IMPLEMENTED);
88 @Override
89 public Cell floor(Cell e) {
90 throw new UnsupportedOperationException(HConstants.NOT_IMPLEMENTED);
93 @Override
94 public SortedSet<Cell> headSet(final Cell toElement) {
95 return headSet(toElement, false);
98 @Override
99 public NavigableSet<Cell> headSet(final Cell toElement,
100 boolean inclusive) {
101 return new CellSet(this.delegatee.headMap(toElement, inclusive), UNKNOWN_NUM_UNIQUES);
104 @Override
105 public Cell higher(Cell e) {
106 throw new UnsupportedOperationException(HConstants.NOT_IMPLEMENTED);
109 @Override
110 public Iterator<Cell> iterator() {
111 return this.delegatee.values().iterator();
114 @Override
115 public Cell lower(Cell e) {
116 throw new UnsupportedOperationException(HConstants.NOT_IMPLEMENTED);
119 @Override
120 public Cell pollFirst() {
121 throw new UnsupportedOperationException(HConstants.NOT_IMPLEMENTED);
124 @Override
125 public Cell pollLast() {
126 throw new UnsupportedOperationException(HConstants.NOT_IMPLEMENTED);
129 @Override
130 public SortedSet<Cell> subSet(Cell fromElement, Cell toElement) {
131 throw new UnsupportedOperationException(HConstants.NOT_IMPLEMENTED);
134 @Override
135 public NavigableSet<Cell> subSet(Cell fromElement,
136 boolean fromInclusive, Cell toElement, boolean toInclusive) {
137 throw new UnsupportedOperationException(HConstants.NOT_IMPLEMENTED);
140 @Override
141 public SortedSet<Cell> tailSet(Cell fromElement) {
142 return tailSet(fromElement, true);
145 @Override
146 public NavigableSet<Cell> tailSet(Cell fromElement, boolean inclusive) {
147 return new CellSet(this.delegatee.tailMap(fromElement, inclusive), UNKNOWN_NUM_UNIQUES);
150 @Override
151 public Comparator<? super Cell> comparator() {
152 throw new UnsupportedOperationException(HConstants.NOT_IMPLEMENTED);
155 @Override
156 public Cell first() {
157 return this.delegatee.firstEntry().getValue();
160 @Override
161 public Cell last() {
162 return this.delegatee.lastEntry().getValue();
165 @Override
166 public boolean add(Cell e) {
167 return this.delegatee.put(e, e) == null;
170 @Override
171 public boolean addAll(Collection<? extends Cell> c) {
172 throw new UnsupportedOperationException(HConstants.NOT_IMPLEMENTED);
175 @Override
176 public void clear() {
177 this.delegatee.clear();
180 @Override
181 public boolean contains(Object o) {
182 //noinspection SuspiciousMethodCalls
183 return this.delegatee.containsKey(o);
186 @Override
187 public boolean containsAll(Collection<?> c) {
188 throw new UnsupportedOperationException(HConstants.NOT_IMPLEMENTED);
191 @Override
192 public boolean isEmpty() {
193 return this.delegatee.isEmpty();
196 @Override
197 public boolean remove(Object o) {
198 return this.delegatee.remove(o) != null;
201 @Override
202 public boolean removeAll(Collection<?> c) {
203 throw new UnsupportedOperationException(HConstants.NOT_IMPLEMENTED);
206 @Override
207 public boolean retainAll(Collection<?> c) {
208 throw new UnsupportedOperationException(HConstants.NOT_IMPLEMENTED);
211 public Cell get(Cell kv) {
212 return this.delegatee.get(kv);
215 @Override
216 public int size() {
217 if (delegatee instanceof ConcurrentSkipListMap) {
218 throw new UnsupportedOperationException("ConcurrentSkipListMap.size() is time-consuming");
220 return this.delegatee.size();
223 @Override
224 public Object[] toArray() {
225 throw new UnsupportedOperationException(HConstants.NOT_IMPLEMENTED);
228 @Override
229 public <T> T[] toArray(T[] a) {
230 throw new UnsupportedOperationException(HConstants.NOT_IMPLEMENTED);
233 public int getNumUniqueKeys() {
234 return numUniqueKeys;