-
Notifications
You must be signed in to change notification settings - Fork 483
/
TypedTable.java
693 lines (599 loc) · 22.1 KB
/
TypedTable.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.apache.hadoop.hdds.utils.db;
import java.io.File;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import com.google.common.annotations.VisibleForTesting;
import org.apache.hadoop.hdds.utils.IOUtils;
import org.apache.hadoop.hdds.utils.MetadataKeyFilters;
import org.apache.hadoop.hdds.utils.TableCacheMetrics;
import org.apache.hadoop.hdds.utils.db.cache.CacheKey;
import org.apache.hadoop.hdds.utils.db.cache.CacheResult;
import org.apache.hadoop.hdds.utils.db.cache.CacheValue;
import org.apache.hadoop.hdds.utils.db.cache.FullTableCache;
import org.apache.hadoop.hdds.utils.db.cache.PartialTableCache;
import org.apache.hadoop.hdds.utils.db.cache.TableCache.CacheType;
import org.apache.hadoop.hdds.utils.db.cache.TableCache;
import org.apache.ratis.util.Preconditions;
import org.apache.ratis.util.function.CheckedBiFunction;
import static org.apache.hadoop.hdds.utils.db.cache.CacheResult.CacheStatus.EXISTS;
import static org.apache.hadoop.hdds.utils.db.cache.CacheResult.CacheStatus.NOT_EXIST;
import static org.apache.ratis.util.JavaUtils.getClassSimpleName;
/**
* Strongly typed table implementation.
* <p>
* Automatically converts values and keys using a raw byte[] based table
* implementation and registered converters.
*
* @param <KEY> type of the keys in the store.
* @param <VALUE> type of the values in the store.
*/
public class TypedTable<KEY, VALUE> implements Table<KEY, VALUE> {
private static final long EPOCH_DEFAULT = -1L;
static final int BUFFER_SIZE_DEFAULT = 4 << 10; // 4 KB
private final RDBTable rawTable;
private final Class<KEY> keyType;
private final Codec<KEY> keyCodec;
private final Class<VALUE> valueType;
private final Codec<VALUE> valueCodec;
private final boolean supportCodecBuffer;
private final CodecBuffer.Capacity bufferCapacity
= new CodecBuffer.Capacity(this, BUFFER_SIZE_DEFAULT);
private final TableCache<KEY, VALUE> cache;
/**
* The same as this(rawTable, codecRegistry, keyType, valueType,
* CacheType.PARTIAL_CACHE).
*/
public TypedTable(RDBTable rawTable,
CodecRegistry codecRegistry, Class<KEY> keyType,
Class<VALUE> valueType) throws IOException {
this(rawTable, codecRegistry, keyType, valueType,
CacheType.PARTIAL_CACHE, "");
}
/**
* Create an TypedTable from the raw table with specified cache type.
*
* @param rawTable The underlying (untyped) table in RocksDB.
* @param codecRegistry To look up codecs.
* @param keyType The key type.
* @param valueType The value type.
* @param cacheType How to cache the entries?
* @param threadNamePrefix
* @throws IOException if failed to iterate the raw table.
*/
public TypedTable(RDBTable rawTable,
CodecRegistry codecRegistry, Class<KEY> keyType,
Class<VALUE> valueType,
CacheType cacheType, String threadNamePrefix) throws IOException {
this.rawTable = Objects.requireNonNull(rawTable, "rawTable==null");
Objects.requireNonNull(codecRegistry, "codecRegistry == null");
this.keyType = Objects.requireNonNull(keyType, "keyType == null");
this.keyCodec = codecRegistry.getCodecFromClass(keyType);
Objects.requireNonNull(keyCodec, "keyCodec == null");
this.valueType = Objects.requireNonNull(valueType, "valueType == null");
this.valueCodec = codecRegistry.getCodecFromClass(valueType);
Objects.requireNonNull(valueCodec, "valueCodec == null");
this.supportCodecBuffer = keyCodec.supportCodecBuffer()
&& valueCodec.supportCodecBuffer();
if (cacheType == CacheType.FULL_CACHE) {
cache = new FullTableCache<>(threadNamePrefix);
//fill cache
try (TableIterator<KEY, ? extends KeyValue<KEY, VALUE>> tableIterator =
iterator()) {
while (tableIterator.hasNext()) {
KeyValue< KEY, VALUE > kv = tableIterator.next();
// We should build cache after OM restart when clean up policy is
// NEVER. Setting epoch value -1, so that when it is marked for
// delete, this will be considered for cleanup.
cache.loadInitial(new CacheKey<>(kv.getKey()),
CacheValue.get(EPOCH_DEFAULT, kv.getValue()));
}
}
} else {
cache = new PartialTableCache<>(threadNamePrefix);
}
}
private CodecBuffer encodeKeyCodecBuffer(KEY key) throws IOException {
return key == null ? null : keyCodec.toDirectCodecBuffer(key);
}
private byte[] encodeKey(KEY key) throws IOException {
return key == null ? null : keyCodec.toPersistedFormat(key);
}
private byte[] encodeValue(VALUE value) throws IOException {
return value == null ? null : valueCodec.toPersistedFormat(value);
}
private KEY decodeKey(byte[] key) throws IOException {
return key == null ? null : keyCodec.fromPersistedFormat(key);
}
private VALUE decodeValue(byte[] value) throws IOException {
return value == null ? null : valueCodec.fromPersistedFormat(value);
}
@Override
public void put(KEY key, VALUE value) throws IOException {
if (supportCodecBuffer) {
try (CodecBuffer k = keyCodec.toDirectCodecBuffer(key);
CodecBuffer v = valueCodec.toDirectCodecBuffer(value)) {
rawTable.put(k.asReadOnlyByteBuffer(), v.asReadOnlyByteBuffer());
}
} else {
rawTable.put(encodeKey(key), encodeValue(value));
}
}
@Override
public void putWithBatch(BatchOperation batch, KEY key, VALUE value)
throws IOException {
if (supportCodecBuffer) {
CodecBuffer keyBuffer = null;
CodecBuffer valueBuffer = null;
try {
keyBuffer = keyCodec.toDirectCodecBuffer(key);
valueBuffer = valueCodec.toDirectCodecBuffer(value);
// The buffers will be released after commit.
rawTable.putWithBatch(batch, keyBuffer, valueBuffer);
} catch (Exception e) {
IOUtils.closeQuietly(valueBuffer, keyBuffer);
throw e;
}
} else {
rawTable.putWithBatch(batch, encodeKey(key), encodeValue(value));
}
}
@Override
public boolean isEmpty() throws IOException {
return rawTable.isEmpty();
}
@Override
public boolean isExist(KEY key) throws IOException {
CacheResult<VALUE> cacheResult =
cache.lookup(new CacheKey<>(key));
if (cacheResult.getCacheStatus() == EXISTS) {
return true;
} else if (cacheResult.getCacheStatus() == NOT_EXIST) {
return false;
} else if (keyCodec.supportCodecBuffer()) {
// keyCodec.supportCodecBuffer() is enough since value is not needed.
try (CodecBuffer inKey = keyCodec.toDirectCodecBuffer(key)) {
// Use zero capacity buffer since value is not needed.
try (CodecBuffer outValue = CodecBuffer.getEmptyBuffer()) {
return getFromTableIfExist(inKey, outValue) != null;
}
}
} else {
return rawTable.isExist(encodeKey(key));
}
}
/**
* Get the value mapped to the given key.
* <p>
* Caller's of this method should use synchronization mechanism, when
* accessing. First it will check from cache, if it has entry return the
* cloned cache value, otherwise get from the RocksDB table.
*
* @param key metadata key
* @return the mapped value; or null if the key is not found.
* @throws IOException when {@link #getFromTable(Object)} throw an exception.
*/
@Override
public VALUE get(KEY key) throws IOException {
// Here the metadata lock will guarantee that cache is not updated for same
// key during get key.
CacheResult<VALUE> cacheResult =
cache.lookup(new CacheKey<>(key));
if (cacheResult.getCacheStatus() == EXISTS) {
return valueCodec.copyObject(cacheResult.getValue().getCacheValue());
} else if (cacheResult.getCacheStatus() == NOT_EXIST) {
return null;
} else {
return getFromTable(key);
}
}
/**
* Skip checking cache and get the value mapped to the given key in byte
* array or returns null if the key is not found.
*
* @param key metadata key
* @return value in byte array or null if the key is not found.
* @throws IOException on Failure
*/
@Override
public VALUE getSkipCache(KEY key) throws IOException {
return getFromTable(key);
}
/**
* This method returns the value if it exists in cache, if it
* does not, get the value from the underlying RockDB table. If it
* exists in cache, it returns the same reference of the cached value.
* <p>
* Caller's of this method should use synchronization mechanism, when
* accessing. First it will check from cache, if it has entry return the
* cached value, otherwise get from the RocksDB table. It is caller
* responsibility not to use the returned object outside the lock.
* <p>
* One example use case of this method is, when validating volume exists in
* bucket requests and also where we need actual value of volume info. Once
* bucket response is added to the double buffer, only bucket info is
* required to flush to DB. So, there is no case of concurrent threads
* modifying the same cached object.
* @param key metadata key
* @return VALUE
* @throws IOException when {@link #getFromTable(Object)} throw an exception.
*/
@Override
public VALUE getReadCopy(KEY key) throws IOException {
// Here the metadata lock will guarantee that cache is not updated for same
// key during get key.
CacheResult<VALUE> cacheResult =
cache.lookup(new CacheKey<>(key));
if (cacheResult.getCacheStatus() == EXISTS) {
return cacheResult.getValue().getCacheValue();
} else if (cacheResult.getCacheStatus() == NOT_EXIST) {
return null;
} else {
return getFromTable(key);
}
}
@Override
public VALUE getIfExist(KEY key) throws IOException {
// Here the metadata lock will guarantee that cache is not updated for same
// key during get key.
CacheResult<VALUE> cacheResult =
cache.lookup(new CacheKey<>(key));
if (cacheResult.getCacheStatus() == EXISTS) {
return valueCodec.copyObject(cacheResult.getValue().getCacheValue());
} else if (cacheResult.getCacheStatus() == NOT_EXIST) {
return null;
} else {
return getFromTableIfExist(key);
}
}
/**
* Use {@link RDBTable#get(ByteBuffer, ByteBuffer)}
* to get a value mapped to the given key.
*
* @param key the buffer containing the key.
* @param outValue the buffer to write the output value.
* When the buffer capacity is smaller than the value size,
* partial value may be written.
* @return null if the key is not found;
* otherwise, return the size of the value.
* @throws IOException in case is an error reading from the db.
*/
private Integer getFromTable(CodecBuffer key, CodecBuffer outValue)
throws IOException {
return outValue.putFromSource(
buffer -> rawTable.get(key.asReadOnlyByteBuffer(), buffer));
}
private VALUE getFromTable(KEY key) throws IOException {
if (supportCodecBuffer) {
return getFromTable(key, this::getFromTable);
} else {
final byte[] keyBytes = encodeKey(key);
byte[] valueBytes = rawTable.get(keyBytes);
return decodeValue(valueBytes);
}
}
/**
* Similar to {@link #getFromTable(CodecBuffer, CodecBuffer)} except that
* this method use {@link RDBTable#getIfExist(ByteBuffer, ByteBuffer)}.
*/
private Integer getFromTableIfExist(CodecBuffer key, CodecBuffer outValue)
throws IOException {
return outValue.putFromSource(
buffer -> rawTable.getIfExist(key.asReadOnlyByteBuffer(), buffer));
}
private VALUE getFromTable(KEY key,
CheckedBiFunction<CodecBuffer, CodecBuffer, Integer, IOException> get)
throws IOException {
try (CodecBuffer inKey = keyCodec.toDirectCodecBuffer(key)) {
for (; ;) {
final Integer required;
final int initial = -bufferCapacity.get(); // resizable
try (CodecBuffer outValue = CodecBuffer.allocateDirect(initial)) {
required = get.apply(inKey, outValue);
if (required == null) {
// key not found
return null;
} else if (required < 0) {
throw new IllegalStateException("required = " + required + " < 0");
}
for (; ;) {
if (required == outValue.readableBytes()) {
// buffer size is big enough
return valueCodec.fromCodecBuffer(outValue);
}
// buffer size too small, try increasing the capacity.
if (!outValue.setCapacity(required)) {
break;
}
// retry with the new capacity
outValue.clear();
final int retried = get.apply(inKey, outValue);
Preconditions.assertSame(required.intValue(), retried, "required");
}
}
// buffer size too small, reallocate a new buffer.
bufferCapacity.increase(required);
}
}
}
private VALUE getFromTableIfExist(KEY key) throws IOException {
if (supportCodecBuffer) {
return getFromTable(key, this::getFromTableIfExist);
} else {
final byte[] keyBytes = encodeKey(key);
final byte[] valueBytes = rawTable.getIfExist(keyBytes);
return decodeValue(valueBytes);
}
}
@Override
public void delete(KEY key) throws IOException {
if (keyCodec.supportCodecBuffer()) {
try (CodecBuffer buffer = keyCodec.toDirectCodecBuffer(key)) {
rawTable.delete(buffer.asReadOnlyByteBuffer());
}
} else {
rawTable.delete(encodeKey(key));
}
}
@Override
public void deleteWithBatch(BatchOperation batch, KEY key)
throws IOException {
rawTable.deleteWithBatch(batch, encodeKey(key));
}
@Override
public void deleteRange(KEY beginKey, KEY endKey) throws IOException {
rawTable.deleteRange(encodeKey(beginKey), encodeKey(endKey));
}
@Override
public Table.KeyValueIterator<KEY, VALUE> iterator() throws IOException {
return iterator(null);
}
@Override
public Table.KeyValueIterator<KEY, VALUE> iterator(KEY prefix)
throws IOException {
if (supportCodecBuffer) {
final CodecBuffer prefixBuffer = encodeKeyCodecBuffer(prefix);
try {
return newCodecBufferTableIterator(rawTable.iterator(prefixBuffer));
} catch (Throwable t) {
if (prefixBuffer != null) {
prefixBuffer.release();
}
throw t;
}
} else {
final byte[] prefixBytes = encodeKey(prefix);
return new TypedTableIterator(rawTable.iterator(prefixBytes));
}
}
@Override
public String getName() {
return rawTable.getName();
}
@Override
public String toString() {
return getClassSimpleName(getClass()) + "-" + getName()
+ "(" + getClassSimpleName(keyType)
+ "->" + getClassSimpleName(valueType) + ")";
}
@Override
public long getEstimatedKeyCount() throws IOException {
if (cache.getCacheType() == CacheType.FULL_CACHE) {
return cache.size();
}
return rawTable.getEstimatedKeyCount();
}
@Override
public void close() throws Exception {
rawTable.close();
}
@Override
public void addCacheEntry(CacheKey<KEY> cacheKey,
CacheValue<VALUE> cacheValue) {
// This will override the entry if there is already entry for this key.
cache.put(cacheKey, cacheValue);
}
@Override
public CacheValue<VALUE> getCacheValue(CacheKey<KEY> cacheKey) {
return cache.get(cacheKey);
}
@Override
public Iterator<Map.Entry<CacheKey<KEY>, CacheValue<VALUE>>> cacheIterator() {
return cache.iterator();
}
@Override
public TableCacheMetrics createCacheMetrics() {
return TableCacheMetrics.create(cache, getName());
}
@Override
public List<TypedKeyValue> getRangeKVs(
KEY startKey, int count, KEY prefix,
MetadataKeyFilters.MetadataKeyFilter... filters)
throws IOException, IllegalArgumentException {
// A null start key means to start from the beginning of the table.
// Cannot convert a null key to bytes.
final byte[] startKeyBytes = encodeKey(startKey);
final byte[] prefixBytes = encodeKey(prefix);
List<? extends KeyValue<byte[], byte[]>> rangeKVBytes =
rawTable.getRangeKVs(startKeyBytes, count, prefixBytes, filters);
List<TypedKeyValue> rangeKVs = new ArrayList<>();
rangeKVBytes.forEach(byteKV -> rangeKVs.add(new TypedKeyValue(byteKV)));
return rangeKVs;
}
@Override
public List<TypedKeyValue> getSequentialRangeKVs(
KEY startKey, int count, KEY prefix,
MetadataKeyFilters.MetadataKeyFilter... filters)
throws IOException, IllegalArgumentException {
// A null start key means to start from the beginning of the table.
// Cannot convert a null key to bytes.
final byte[] startKeyBytes = encodeKey(startKey);
final byte[] prefixBytes = encodeKey(prefix);
List<? extends KeyValue<byte[], byte[]>> rangeKVBytes =
rawTable.getSequentialRangeKVs(startKeyBytes, count,
prefixBytes, filters);
List<TypedKeyValue> rangeKVs = new ArrayList<>();
rangeKVBytes.forEach(byteKV -> rangeKVs.add(new TypedKeyValue(byteKV)));
return rangeKVs;
}
@Override
public void deleteBatchWithPrefix(BatchOperation batch, KEY prefix)
throws IOException {
rawTable.deleteBatchWithPrefix(batch, encodeKey(prefix));
}
@Override
public void dumpToFileWithPrefix(File externalFile, KEY prefix)
throws IOException {
rawTable.dumpToFileWithPrefix(externalFile, encodeKey(prefix));
}
@Override
public void loadFromFile(File externalFile) throws IOException {
rawTable.loadFromFile(externalFile);
}
@Override
public void cleanupCache(List<Long> epochs) {
cache.cleanup(epochs);
}
@VisibleForTesting
TableCache<KEY, VALUE> getCache() {
return cache;
}
/**
* Key value implementation for strongly typed tables.
*/
public final class TypedKeyValue implements KeyValue<KEY, VALUE> {
private final KeyValue<byte[], byte[]> rawKeyValue;
private TypedKeyValue(KeyValue<byte[], byte[]> rawKeyValue) {
this.rawKeyValue = rawKeyValue;
}
@Override
public KEY getKey() throws IOException {
return decodeKey(rawKeyValue.getKey());
}
@Override
public VALUE getValue() throws IOException {
return decodeValue(rawKeyValue.getValue());
}
}
RawIterator<CodecBuffer> newCodecBufferTableIterator(
TableIterator<CodecBuffer, KeyValue<CodecBuffer, CodecBuffer>> i) {
return new RawIterator<CodecBuffer>(i) {
@Override
AutoCloseSupplier<CodecBuffer> convert(KEY key) throws IOException {
final CodecBuffer buffer = encodeKeyCodecBuffer(key);
return new AutoCloseSupplier<CodecBuffer>() {
@Override
public void close() {
buffer.release();
}
@Override
public CodecBuffer get() {
return buffer;
}
};
}
@Override
KeyValue<KEY, VALUE> convert(KeyValue<CodecBuffer, CodecBuffer> raw)
throws IOException {
final KEY key = keyCodec.fromCodecBuffer(raw.getKey());
final VALUE value = valueCodec.fromCodecBuffer(raw.getValue());
return Table.newKeyValue(key, value);
}
};
}
/**
* Table Iterator implementation for strongly typed tables.
*/
public class TypedTableIterator extends RawIterator<byte[]> {
TypedTableIterator(
TableIterator<byte[], KeyValue<byte[], byte[]>> rawIterator) {
super(rawIterator);
}
@Override
AutoCloseSupplier<byte[]> convert(KEY key) throws IOException {
final byte[] keyArray = encodeKey(key);
return () -> keyArray;
}
@Override
KeyValue<KEY, VALUE> convert(KeyValue<byte[], byte[]> raw) {
return new TypedKeyValue(raw);
}
}
/**
* A {@link Table.KeyValueIterator} backed by a raw iterator.
*
* @param <RAW> The raw type.
*/
abstract class RawIterator<RAW>
implements Table.KeyValueIterator<KEY, VALUE> {
private final TableIterator<RAW, KeyValue<RAW, RAW>> rawIterator;
RawIterator(TableIterator<RAW, KeyValue<RAW, RAW>> rawIterator) {
this.rawIterator = rawIterator;
}
/** Covert the given key to the {@link RAW} type. */
abstract AutoCloseSupplier<RAW> convert(KEY key) throws IOException;
/**
* Covert the given {@link Table.KeyValue}
* from ({@link RAW}, {@link RAW}) to ({@link KEY}, {@link VALUE}).
*/
abstract KeyValue<KEY, VALUE> convert(KeyValue<RAW, RAW> raw)
throws IOException;
@Override
public void seekToFirst() {
rawIterator.seekToFirst();
}
@Override
public void seekToLast() {
rawIterator.seekToLast();
}
@Override
public KeyValue<KEY, VALUE> seek(KEY key) throws IOException {
try (AutoCloseSupplier<RAW> rawKey = convert(key)) {
final KeyValue<RAW, RAW> result = rawIterator.seek(rawKey.get());
return result == null ? null : convert(result);
}
}
@Override
public void close() throws IOException {
rawIterator.close();
}
@Override
public boolean hasNext() {
return rawIterator.hasNext();
}
@Override
public KeyValue<KEY, VALUE> next() {
try {
return convert(rawIterator.next());
} catch (IOException e) {
throw new IllegalStateException("Failed next()", e);
}
}
@Override
public void removeFromDB() throws IOException {
rawIterator.removeFromDB();
}
}
}