From 52ac94e0001c9985d2f71e15b3a53e1e7c476159 Mon Sep 17 00:00:00 2001 From: Tsz-Wo Nicholas Sze Date: Wed, 16 Oct 2024 21:00:22 -0700 Subject: [PATCH] HDDS-11589. ReconSCMDBDefinition should be singleton. --- .../ozone/recon/scm/ReconSCMDBDefinition.java | 18 ++++++++++-------- .../ReconStorageContainerManagerFacade.java | 6 ++---- .../scm/AbstractReconContainerManagerTest.java | 2 +- .../ozone/recon/scm/TestReconNodeManager.java | 2 +- .../recon/scm/TestReconPipelineManager.java | 2 +- .../ozone/debug/DBDefinitionFactory.java | 2 +- .../ozone/debug/TestDBDefinitionFactory.java | 3 +-- 7 files changed, 17 insertions(+), 18 deletions(-) diff --git a/hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/scm/ReconSCMDBDefinition.java b/hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/scm/ReconSCMDBDefinition.java index e8a6949f21e..4970d5da915 100644 --- a/hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/scm/ReconSCMDBDefinition.java +++ b/hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/scm/ReconSCMDBDefinition.java @@ -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_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 - NODES = - new DBColumnFamilyDefinition( - "nodes", - UUID_CODEC, - DatanodeDetails.getCodec()); + public static final DBColumnFamilyDefinition NODES + = new DBColumnFamilyDefinition<>("nodes", UUID_CODEC, DatanodeDetails.getCodec()); private static final Map> 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); } diff --git a/hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/scm/ReconStorageContainerManagerFacade.java b/hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/scm/ReconStorageContainerManagerFacade.java index c773187c4b1..ea1a3440160 100644 --- a/hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/scm/ReconStorageContainerManagerFacade.java +++ b/hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/scm/ReconStorageContainerManagerFacade.java @@ -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()); @@ -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 nodeTable = ReconSCMDBDefinition.NODES.getTable(dbStore); Table newNodeTable = diff --git a/hadoop-ozone/recon/src/test/java/org/apache/hadoop/ozone/recon/scm/AbstractReconContainerManagerTest.java b/hadoop-ozone/recon/src/test/java/org/apache/hadoop/ozone/recon/scm/AbstractReconContainerManagerTest.java index eb62b7d3ece..939279fc17b 100644 --- a/hadoop-ozone/recon/src/test/java/org/apache/hadoop/ozone/recon/scm/AbstractReconContainerManagerTest.java +++ b/hadoop-ozone/recon/src/test/java/org/apache/hadoop/ozone/recon/scm/AbstractReconContainerManagerTest.java @@ -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( diff --git a/hadoop-ozone/recon/src/test/java/org/apache/hadoop/ozone/recon/scm/TestReconNodeManager.java b/hadoop-ozone/recon/src/test/java/org/apache/hadoop/ozone/recon/scm/TestReconNodeManager.java index 02207f9c620..f17eb78d89c 100644 --- a/hadoop-ozone/recon/src/test/java/org/apache/hadoop/ozone/recon/scm/TestReconNodeManager.java +++ b/hadoop-ozone/recon/src/test/java/org/apache/hadoop/ozone/recon/scm/TestReconNodeManager.java @@ -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); } diff --git a/hadoop-ozone/recon/src/test/java/org/apache/hadoop/ozone/recon/scm/TestReconPipelineManager.java b/hadoop-ozone/recon/src/test/java/org/apache/hadoop/ozone/recon/scm/TestReconPipelineManager.java index d723ee75e85..302772e40fd 100644 --- a/hadoop-ozone/recon/src/test/java/org/apache/hadoop/ozone/recon/scm/TestReconPipelineManager.java +++ b/hadoop-ozone/recon/src/test/java/org/apache/hadoop/ozone/recon/scm/TestReconPipelineManager.java @@ -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(); diff --git a/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/debug/DBDefinitionFactory.java b/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/debug/DBDefinitionFactory.java index 2f9c39db275..87482cb549b 100644 --- a/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/debug/DBDefinitionFactory.java +++ b/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/debug/DBDefinitionFactory.java @@ -56,7 +56,7 @@ private DBDefinitionFactory() { static { final Map 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); } diff --git a/hadoop-ozone/tools/src/test/java/org/apache/hadoop/ozone/debug/TestDBDefinitionFactory.java b/hadoop-ozone/tools/src/test/java/org/apache/hadoop/ozone/debug/TestDBDefinitionFactory.java index b39865ce9d5..5f0be7859d4 100644 --- a/hadoop-ozone/tools/src/test/java/org/apache/hadoop/ozone/debug/TestDBDefinitionFactory.java +++ b/hadoop-ozone/tools/src/test/java/org/apache/hadoop/ozone/debug/TestDBDefinitionFactory.java @@ -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(