Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
package org.apache.hadoop.ozone.container.metadata;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import org.apache.hadoop.hdds.utils.MetadataKeyFilters;
import org.apache.hadoop.hdds.utils.db.BatchOperation;
import org.apache.hadoop.hdds.utils.db.Table;
Expand Down Expand Up @@ -145,39 +145,13 @@ private static String unprefix(String key) {
private static List<KeyValue<String, ChunkInfoList>> unprefix(
List<? extends KeyValue<String, ChunkInfoList>> kvs) {

List<KeyValue<String, ChunkInfoList>> processedKVs = new ArrayList<>();
kvs.forEach(kv -> processedKVs.add(new UnprefixedKeyValue(kv)));

return processedKVs;
return kvs.stream()
.map(kv -> Table.newKeyValue(unprefix(kv.getKey()), kv.getValue()))
.collect(Collectors.toList());
}

private static MetadataKeyFilters.KeyPrefixFilter getDeletedFilter() {
return (new MetadataKeyFilters.KeyPrefixFilter())
.addFilter(DELETED_KEY_PREFIX);
}

/**
* {@link KeyValue} implementation that removes the deleted key prefix from
* an existing {@link KeyValue}.
*/
private static class UnprefixedKeyValue implements KeyValue<String,
ChunkInfoList> {

private final KeyValue<String, ChunkInfoList> prefixedKeyValue;

UnprefixedKeyValue(
KeyValue<String, ChunkInfoList> prefixedKeyValue) {
this.prefixedKeyValue = prefixedKeyValue;
}

@Override
public String getKey() throws IOException {
return unprefix(prefixedKeyValue.getKey());
}

@Override
public ChunkInfoList getValue() throws IOException {
return prefixedKeyValue.getValue();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ byte[] key() {
@Override
Table.KeyValue<byte[], byte[]> getKeyValue() {
final ManagedRocksIterator i = getRocksDBIterator();
return RawKeyValue.create(i.get().key(), i.get().value());
return Table.newKeyValue(i.get().key(), i.get().value());
}

@Override
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -325,94 +325,58 @@ void deleteBatchWithPrefix(BatchOperation batch, KEY prefix)
/**
* Class used to represent the key and value pair of a db entry.
*/
interface KeyValue<KEY, VALUE> {

KEY getKey() throws IOException;
final class KeyValue<K, V> {
private final K key;
private final V value;
private final int rawSize;

private KeyValue(K key, V value, int rawSize) {
this.key = key;
this.value = value;
this.rawSize = rawSize;
}

VALUE getValue() throws IOException;
public K getKey() {
return key;
}

default int getRawSize() throws IOException {
return 0;
public V getValue() {
return value;
}
}

static <K, V> KeyValue<K, V> newKeyValue(K key, V value) {
return new KeyValue<K, V>() {
@Override
public K getKey() {
return key;
}
public int getRawSize() {
return rawSize;
}

@Override
public V getValue() {
return value;
}
@Override
public String toString() {
return "(key=" + key + ", value=" + value + ")";
}

@Override
public String toString() {
return "(key=" + key + ", value=" + value + ")";
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
} else if (!(obj instanceof KeyValue)) {
return false;
}
final KeyValue<?, ?> that = (KeyValue<?, ?>) obj;
return this.getKey().equals(that.getKey())
&& this.getValue().equals(that.getValue());
}

@Override
public boolean equals(Object obj) {
if (!(obj instanceof KeyValue)) {
return false;
}
KeyValue<?, ?> kv = (KeyValue<?, ?>) obj;
try {
return getKey().equals(kv.getKey()) && getValue().equals(kv.getValue());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
@Override
public int hashCode() {
return Objects.hash(getKey(), getValue());
}
}

@Override
public int hashCode() {
return Objects.hash(getKey(), getValue());
}
};
static <K, V> KeyValue<K, V> newKeyValue(K key, V value) {
return newKeyValue(key, value, 0);
}

static <K, V> KeyValue<K, V> newKeyValue(K key, V value, int rawSize) {
return new KeyValue<K, V>() {
@Override
public K getKey() {
return key;
}

@Override
public V getValue() {
return value;
}

@Override
public int getRawSize() throws IOException {
return rawSize;
}

@Override
public String toString() {
return "(key=" + key + ", value=" + value + ")";
}

@Override
public boolean equals(Object obj) {
if (!(obj instanceof KeyValue)) {
return false;
}
KeyValue<?, ?> kv = (KeyValue<?, ?>) obj;
try {
return getKey().equals(kv.getKey()) && getValue().equals(kv.getValue());
} catch (IOException e) {
throw new RuntimeException(e);
}
}

@Override
public int hashCode() {
return Objects.hash(getKey(), getValue());
}
};
return new KeyValue<>(key, value, rawSize);
}

/** A {@link TableIterator} to iterate {@link KeyValue}s. */
Expand Down
Loading
Loading