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 @@ -17,12 +17,16 @@

package org.apache.hadoop.hdds.utils.db;

import static org.apache.ratis.util.JavaUtils.getClassSimpleName;

import java.io.IOException;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import org.apache.hadoop.hdds.utils.CollectionUtils;
import org.apache.hadoop.hdds.utils.db.cache.TableCache.CacheType;
import org.apache.hadoop.hdds.utils.db.managed.ManagedColumnFamilyOptions;

/**
Expand All @@ -34,17 +38,18 @@
public class DBColumnFamilyDefinition<KEY, VALUE> {

private final String tableName;

private final Codec<KEY> keyCodec;

private final Codec<VALUE> valueCodec;
private final String name;

private volatile ManagedColumnFamilyOptions cfOptions;

public DBColumnFamilyDefinition(String tableName, Codec<KEY> keyCodec, Codec<VALUE> valueCodec) {
this.tableName = tableName;
this.keyCodec = keyCodec;
this.valueCodec = valueCodec;
this.tableName = Objects.requireNonNull(tableName, "tableName == null");
this.keyCodec = Objects.requireNonNull(keyCodec, "keyCodec == null");
this.valueCodec = Objects.requireNonNull(valueCodec, "valueCodec == null");
this.name = tableName + "-def: " + getClassSimpleName(getKeyType())
+ " -> " + getClassSimpleName(getValueType());
this.cfOptions = null;
}

Expand All @@ -67,8 +72,12 @@ public DBColumnFamilyDefinition(String tableName, Codec<KEY> keyCodec, Codec<VAL
DBColumnFamilyDefinition::getName);
}

public Table<KEY, VALUE> getTable(DBStore db) throws IOException {
return db.getTable(tableName, getKeyType(), getValueType());
public TypedTable<KEY, VALUE> getTable(DBStore db) throws IOException {
return db.getTable(tableName, keyCodec, valueCodec);
}

public TypedTable<KEY, VALUE> getTable(DBStore db, CacheType cacheType) throws IOException {
return db.getTable(tableName, keyCodec, valueCodec, cacheType);
}

public String getName() {
Expand Down Expand Up @@ -98,4 +107,9 @@ public ManagedColumnFamilyOptions getCfOptions() {
public void setCfOptions(ManagedColumnFamilyOptions cfOptions) {
this.cfOptions = cfOptions;
}

@Override
public String toString() {
return name;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.util.Map;
import org.apache.hadoop.hdds.annotation.InterfaceStability;
import org.apache.hadoop.hdds.utils.db.cache.TableCache;
import org.apache.hadoop.hdds.utils.db.cache.TableCache.CacheType;
import org.apache.ozone.rocksdiff.RocksDBCheckpointDiffer;

/**
Expand All @@ -45,6 +46,11 @@ public interface DBStore extends Closeable, BatchOperationHandler {
*/
Table<byte[], byte[]> getTable(String name) throws IOException;

/** The same as getTable(name, keyCodec, valueCodec, CacheType.PARTIAL_CACHE). */
default <KEY, VALUE> TypedTable<KEY, VALUE> getTable(String name, Codec<KEY> keyCodec, Codec<VALUE> valueCodec)
throws IOException {
return getTable(name, keyCodec, valueCodec, CacheType.PARTIAL_CACHE);
}

/**
* Gets an existing TableStore with implicit key/value conversion and
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,10 @@
import org.apache.hadoop.hdds.security.x509.CertificateTestUtils;
import org.apache.hadoop.hdds.security.x509.certificate.client.SCMCertificateClient;
import org.apache.hadoop.hdds.utils.TransactionInfo;
import org.apache.hadoop.hdds.utils.db.Codec;
import org.apache.hadoop.hdds.utils.db.DBCheckpoint;
import org.apache.hadoop.hdds.utils.db.DBStore;
import org.apache.hadoop.hdds.utils.db.Table;
import org.apache.hadoop.hdds.utils.db.TypedTable;
import org.apache.hadoop.ozone.OzoneConfigKeys;
import org.apache.ozone.test.GenericTestUtils.PortAllocator;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -172,7 +173,7 @@ private SCMMetadataStore metadataStore() throws IOException {

private DBStore dbStore() throws IOException {
DBStore dbStoreMock = mock(DBStore.class);
doReturn(trInfoTable()).when(dbStoreMock).getTable(any(), any(), any());
doReturn(trInfoTable()).when(dbStoreMock).getTable(any(), (Codec<?>) any(), any());
doReturn(checkPoint()).when(dbStoreMock).getCheckpoint(anyBoolean());
return dbStoreMock;
}
Expand All @@ -186,9 +187,9 @@ private DBCheckpoint checkPoint() throws IOException {
return checkpoint;
}

private Table<String, TransactionInfo> trInfoTable()
private TypedTable<String, TransactionInfo> trInfoTable()
throws IOException {
Table<String, TransactionInfo> tableMock = mock(Table.class);
final TypedTable<String, TransactionInfo> tableMock = mock(TypedTable.class);
doReturn(mock(TransactionInfo.class)).when(tableMock).get(any());
return tableMock;
}
Expand Down
Loading