Skip to content

Commit

Permalink
HDDS-11557. Simplify DBColumnFamilyDefinition. (apache#7298)
Browse files Browse the repository at this point in the history
(cherry picked from commit 8eef589)
  • Loading branch information
szetszwo authored Oct 13, 2024
1 parent eb97251 commit 9a78774
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 123 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,27 +51,21 @@ public class DatanodeSchemaOneDBDefinition
BLOCK_DATA =
new DBColumnFamilyDefinition<>(
StringUtils.bytes2String(DEFAULT_COLUMN_FAMILY),
String.class,
SchemaOneKeyCodec.get(),
BlockData.class,
BlockData.getCodec());

public static final DBColumnFamilyDefinition<String, Long>
METADATA =
new DBColumnFamilyDefinition<>(
StringUtils.bytes2String(DEFAULT_COLUMN_FAMILY),
String.class,
SchemaOneKeyCodec.get(),
Long.class,
LongCodec.get());

public static final DBColumnFamilyDefinition<String, ChunkInfoList>
DELETED_BLOCKS =
new DBColumnFamilyDefinition<>(
StringUtils.bytes2String(DEFAULT_COLUMN_FAMILY),
String.class,
SchemaOneKeyCodec.get(),
ChunkInfoList.class,
SchemaOneChunkInfoListCodec.get());

private static final Map<String, List<DBColumnFamilyDefinition<?, ?>>>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,45 +59,35 @@ public class DatanodeSchemaThreeDBDefinition
BLOCK_DATA =
new DBColumnFamilyDefinition<>(
"block_data",
String.class,
FixedLengthStringCodec.get(),
BlockData.class,
BlockData.getCodec());

public static final DBColumnFamilyDefinition<String, Long>
METADATA =
new DBColumnFamilyDefinition<>(
"metadata",
String.class,
FixedLengthStringCodec.get(),
Long.class,
LongCodec.get());

public static final DBColumnFamilyDefinition<String, DeletedBlocksTransaction>
DELETE_TRANSACTION =
new DBColumnFamilyDefinition<>(
"delete_txns",
String.class,
FixedLengthStringCodec.get(),
DeletedBlocksTransaction.class,
Proto2Codec.get(DeletedBlocksTransaction.getDefaultInstance()));

public static final DBColumnFamilyDefinition<String, Long>
FINALIZE_BLOCKS =
new DBColumnFamilyDefinition<>(
"finalize_blocks",
String.class,
FixedLengthStringCodec.get(),
Long.class,
LongCodec.get());

public static final DBColumnFamilyDefinition<String, BlockData>
LAST_CHUNK_INFO =
new DBColumnFamilyDefinition<>(
"last_chunk_info",
String.class,
FixedLengthStringCodec.get(),
BlockData.class,
BlockData.getCodec());

private static String separator = "";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
package org.apache.hadoop.ozone.container.metadata;

import org.apache.hadoop.hdds.conf.ConfigurationSource;
import org.apache.hadoop.hdds.protocol.proto.StorageContainerDatanodeProtocolProtos;
import org.apache.hadoop.hdds.utils.db.DBColumnFamilyDefinition;
import org.apache.hadoop.hdds.utils.db.DBDefinition;
import org.apache.hadoop.hdds.utils.db.FixedLengthStringCodec;
Expand All @@ -44,45 +43,35 @@ public class DatanodeSchemaTwoDBDefinition
BLOCK_DATA =
new DBColumnFamilyDefinition<>(
"block_data",
String.class,
StringCodec.get(),
BlockData.class,
BlockData.getCodec());

public static final DBColumnFamilyDefinition<String, Long>
METADATA =
new DBColumnFamilyDefinition<>(
"metadata",
String.class,
StringCodec.get(),
Long.class,
LongCodec.get());

public static final DBColumnFamilyDefinition<Long, DeletedBlocksTransaction>
DELETE_TRANSACTION =
new DBColumnFamilyDefinition<>(
"delete_txns",
Long.class,
LongCodec.get(),
StorageContainerDatanodeProtocolProtos.DeletedBlocksTransaction.class,
Proto2Codec.get(DeletedBlocksTransaction.getDefaultInstance()));

public static final DBColumnFamilyDefinition<String, Long>
FINALIZE_BLOCKS =
new DBColumnFamilyDefinition<>(
"finalize_blocks",
String.class,
FixedLengthStringCodec.get(),
Long.class,
LongCodec.get());

public static final DBColumnFamilyDefinition<String, BlockData>
LAST_CHUNK_INFO =
new DBColumnFamilyDefinition<>(
"last_chunk_info",
String.class,
FixedLengthStringCodec.get(),
BlockData.class,
BlockData.getCodec());

public DatanodeSchemaTwoDBDefinition(String dbPath,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,48 +54,37 @@ public class DBColumnFamilyDefinition<KEY, VALUE> {

private final String tableName;

private final Class<KEY> keyType;

private final Codec<KEY> keyCodec;

private final Class<VALUE> valueType;

private final Codec<VALUE> valueCodec;

private ManagedColumnFamilyOptions cfOptions;
private volatile ManagedColumnFamilyOptions cfOptions;

public DBColumnFamilyDefinition(
String tableName,
Class<KEY> keyType,
Codec<KEY> keyCodec,
Class<VALUE> valueType,
Codec<VALUE> valueCodec) {
public DBColumnFamilyDefinition(String tableName, Codec<KEY> keyCodec, Codec<VALUE> valueCodec) {
this.tableName = tableName;
this.keyType = keyType;
this.keyCodec = keyCodec;
this.valueType = valueType;
this.valueCodec = valueCodec;
this.cfOptions = null;
}

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

public String getName() {
return tableName;
}

public Class<KEY> getKeyType() {
return keyType;
return keyCodec.getTypeClass();
}

public Codec<KEY> getKeyCodec() {
return keyCodec;
}

public Class<VALUE> getValueType() {
return valueType;
return valueCodec.getTypeClass();
}

public Codec<VALUE> getValueCodec() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ public void builderWithColumnFamilyOptions(@TempDir Path tempDir)
String sampleTableName = "sampleTable";
final DBColumnFamilyDefinition<String, Long> sampleTable =
new DBColumnFamilyDefinition<>(sampleTableName,
String.class, StringCodec.get(), Long.class, LongCodec.get());
StringCodec.get(), LongCodec.get());
final DBDefinition sampleDB = new DBDefinition.WithMap(
DBColumnFamilyDefinition.newUnmodifiableMap(sampleTable)) {
{
Expand Down Expand Up @@ -250,8 +250,8 @@ public void testIfAutoCompactionDisabled(boolean disableAutoCompaction,

String sampleTableName = "sampleTable";
final DBColumnFamilyDefinition<String, Long> sampleTable =
new DBColumnFamilyDefinition<>(sampleTableName, String.class,
StringCodec.get(), Long.class, LongCodec.get());
new DBColumnFamilyDefinition<>(sampleTableName,
StringCodec.get(), LongCodec.get());
final DBDefinition sampleDB = new DBDefinition.WithMap(
DBColumnFamilyDefinition.newUnmodifiableMap(sampleTable)) {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,73 +45,57 @@ public class SCMDBDefinition extends DBDefinition.WithMap {
DELETED_BLOCKS =
new DBColumnFamilyDefinition<>(
"deletedBlocks",
Long.class,
LongCodec.get(),
DeletedBlocksTransaction.class,
Proto2Codec.get(DeletedBlocksTransaction.getDefaultInstance()));

public static final DBColumnFamilyDefinition<BigInteger, X509Certificate>
VALID_CERTS =
new DBColumnFamilyDefinition<>(
"validCerts",
BigInteger.class,
BigIntegerCodec.get(),
X509Certificate.class,
X509CertificateCodec.get());

public static final DBColumnFamilyDefinition<BigInteger, X509Certificate>
VALID_SCM_CERTS =
new DBColumnFamilyDefinition<>(
"validSCMCerts",
BigInteger.class,
BigIntegerCodec.get(),
X509Certificate.class,
X509CertificateCodec.get());

public static final DBColumnFamilyDefinition<PipelineID, Pipeline>
PIPELINES =
new DBColumnFamilyDefinition<>(
"pipelines",
PipelineID.class,
PipelineID.getCodec(),
Pipeline.class,
Pipeline.getCodec());

public static final DBColumnFamilyDefinition<ContainerID, ContainerInfo>
CONTAINERS =
new DBColumnFamilyDefinition<>(
"containers",
ContainerID.class,
ContainerID.getCodec(),
ContainerInfo.class,
ContainerInfo.getCodec());

public static final DBColumnFamilyDefinition<String, TransactionInfo>
TRANSACTIONINFO =
new DBColumnFamilyDefinition<>(
"scmTransactionInfos",
String.class,
StringCodec.get(),
TransactionInfo.class,
TransactionInfo.getCodec());

public static final DBColumnFamilyDefinition<String, Long>
SEQUENCE_ID =
new DBColumnFamilyDefinition<>(
"sequenceId",
String.class,
StringCodec.get(),
Long.class,
LongCodec.get());

public static final DBColumnFamilyDefinition<ContainerID,
MoveDataNodePair>
MOVE =
new DBColumnFamilyDefinition<>(
"move",
ContainerID.class,
ContainerID.getCodec(),
MoveDataNodePair.class,
MoveDataNodePair.getCodec());

/**
Expand All @@ -121,18 +105,14 @@ public class SCMDBDefinition extends DBDefinition.WithMap {
public static final DBColumnFamilyDefinition<String, String>
META = new DBColumnFamilyDefinition<>(
"meta",
String.class,
StringCodec.get(),
String.class,
StringCodec.get());

public static final DBColumnFamilyDefinition<String, ByteString>
STATEFUL_SERVICE_CONFIG =
new DBColumnFamilyDefinition<>(
"statefulServiceConfig",
String.class,
StringCodec.get(),
ByteString.class,
ByteStringCodec.get());

private static final Map<String, DBColumnFamilyDefinition<?, ?>>
Expand Down
Loading

0 comments on commit 9a78774

Please sign in to comment.