Skip to content

Commit

Permalink
HDDS-11589. ReconSCMDBDefinition should be singleton. (apache#7323)
Browse files Browse the repository at this point in the history
  • Loading branch information
szetszwo authored Oct 17, 2024
1 parent f784a84 commit 9b66267
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,25 +32,27 @@
/**
* Recon SCM db file for ozone.
*/
public class ReconSCMDBDefinition extends SCMDBDefinition {
public final class ReconSCMDBDefinition extends SCMDBDefinition {
private static final Codec<UUID> UUID_CODEC = new DelegatedCodec<>(
StringCodec.get(), UUID::fromString, UUID::toString,
UUID.class, DelegatedCodec.CopyType.SHALLOW);

public static final String RECON_SCM_DB_NAME = "recon-scm.db";

public static final DBColumnFamilyDefinition<UUID, DatanodeDetails>
NODES =
new DBColumnFamilyDefinition<UUID, DatanodeDetails>(
"nodes",
UUID_CODEC,
DatanodeDetails.getCodec());
public static final DBColumnFamilyDefinition<UUID, DatanodeDetails> NODES
= new DBColumnFamilyDefinition<>("nodes", UUID_CODEC, DatanodeDetails.getCodec());

private static final Map<String, DBColumnFamilyDefinition<?, ?>>
COLUMN_FAMILIES = DBColumnFamilyDefinition.newUnmodifiableMap(
SCMDBDefinition.get().getMap(), NODES);

public ReconSCMDBDefinition() {
private static final ReconSCMDBDefinition INSTANCE = new ReconSCMDBDefinition();

public static ReconSCMDBDefinition get() {
return INSTANCE;
}

private ReconSCMDBDefinition() {
super(COLUMN_FAMILIES);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,7 @@ public ReconStorageContainerManagerFacade(OzoneConfiguration conf,

this.scmStorageConfig = new ReconStorageConfig(conf, reconUtils);
this.clusterMap = new NetworkTopologyImpl(conf);
this.dbStore = DBStoreBuilder
.createDBStore(ozoneConfiguration, new ReconSCMDBDefinition());
this.dbStore = DBStoreBuilder.createDBStore(ozoneConfiguration, ReconSCMDBDefinition.get());

this.scmLayoutVersionManager =
new HDDSLayoutVersionManager(scmStorageConfig.getLayoutVersion());
Expand Down Expand Up @@ -627,8 +626,7 @@ private void deleteOldSCMDB() throws IOException {

private void initializeNewRdbStore(File dbFile) throws IOException {
try {
DBStore newStore = createDBAndAddSCMTablesAndCodecs(
dbFile, new ReconSCMDBDefinition());
final DBStore newStore = createDBAndAddSCMTablesAndCodecs(dbFile, ReconSCMDBDefinition.get());
Table<UUID, DatanodeDetails> nodeTable =
ReconSCMDBDefinition.NODES.getTable(dbStore);
Table<UUID, DatanodeDetails> newNodeTable =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public void setUp(@TempDir File tempDir) throws Exception {
conf = new OzoneConfiguration();
conf.set(OZONE_METADATA_DIRS, tempDir.getAbsolutePath());
conf.set(OZONE_SCM_NAMES, "localhost");
store = DBStoreBuilder.createDBStore(conf, new ReconSCMDBDefinition());
store = DBStoreBuilder.createDBStore(conf, ReconSCMDBDefinition.get());
scmhaManager = SCMHAManagerStub.getInstance(
true, new SCMHADBTransactionBufferStub(store));
sequenceIdGen = new SequenceIdGenerator(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public void setUp() throws Exception {
reconStorageConfig = new ReconStorageConfig(conf, reconUtils);
versionManager = new HDDSLayoutVersionManager(
reconStorageConfig.getLayoutVersion());
store = DBStoreBuilder.createDBStore(conf, new ReconSCMDBDefinition());
store = DBStoreBuilder.createDBStore(conf, ReconSCMDBDefinition.get());
reconContext = new ReconContext(conf, reconUtils);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public void setup() throws IOException {
temporaryFolder.toAbsolutePath().toString());
conf.set(OZONE_SCM_NAMES, "localhost");
scmStorageConfig = new ReconStorageConfig(conf, new ReconUtils());
store = DBStoreBuilder.createDBStore(conf, new ReconSCMDBDefinition());
store = DBStoreBuilder.createDBStore(conf, ReconSCMDBDefinition.get());
scmhaManager = SCMHAManagerStub.getInstance(
true, new SCMHADBTransactionBufferStub(store));
scmContext = SCMContext.emptyContext();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ private DBDefinitionFactory() {

static {
final Map<String, DBDefinition> map = new HashMap<>();
Arrays.asList(SCMDBDefinition.get(), OMDBDefinition.get(), new ReconSCMDBDefinition())
Arrays.asList(SCMDBDefinition.get(), OMDBDefinition.get(), ReconSCMDBDefinition.get())
.forEach(dbDefinition -> map.put(dbDefinition.getName(), dbDefinition));
DB_MAP = Collections.unmodifiableMap(map);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ public void testGetDefinition() {
definition = DBDefinitionFactory.getDefinition(SCMDBDefinition.get().getName());
assertInstanceOf(SCMDBDefinition.class, definition);

definition = DBDefinitionFactory.getDefinition(
new ReconSCMDBDefinition().getName());
definition = DBDefinitionFactory.getDefinition(ReconSCMDBDefinition.get().getName());
assertInstanceOf(ReconSCMDBDefinition.class, definition);

definition = DBDefinitionFactory.getDefinition(
Expand Down

0 comments on commit 9b66267

Please sign in to comment.