Search in sources :

Example 1 with OMDBDefinition

use of org.apache.hadoop.ozone.om.codec.OMDBDefinition in project ozone by apache.

the class TestDBDefinitionFactory method testGetDefinition.

@Test
public void testGetDefinition() {
    DBDefinition definition = DBDefinitionFactory.getDefinition(new OMDBDefinition().getName());
    assertTrue(definition instanceof OMDBDefinition);
    definition = DBDefinitionFactory.getDefinition(new SCMDBDefinition().getName());
    assertTrue(definition instanceof SCMDBDefinition);
    definition = DBDefinitionFactory.getDefinition(new ReconSCMDBDefinition().getName());
    assertTrue(definition instanceof ReconSCMDBDefinition);
    definition = DBDefinitionFactory.getDefinition(RECON_OM_SNAPSHOT_DB + "_1");
    assertTrue(definition instanceof OMDBDefinition);
    definition = DBDefinitionFactory.getDefinition(RECON_CONTAINER_KEY_DB + "_1");
    assertTrue(definition instanceof ReconDBDefinition);
    DBDefinitionFactory.setDnDBSchemaVersion("V2");
    definition = DBDefinitionFactory.getDefinition(Paths.get("/tmp/test-container.db"));
    assertTrue(definition instanceof DatanodeSchemaTwoDBDefinition);
    DBDefinitionFactory.setDnDBSchemaVersion("V1");
    definition = DBDefinitionFactory.getDefinition(Paths.get("/tmp/test-container.db"));
    assertTrue(definition instanceof DatanodeSchemaOneDBDefinition);
}
Also used : ReconSCMDBDefinition(org.apache.hadoop.ozone.recon.scm.ReconSCMDBDefinition) DatanodeSchemaOneDBDefinition(org.apache.hadoop.ozone.container.metadata.DatanodeSchemaOneDBDefinition) SCMDBDefinition(org.apache.hadoop.hdds.scm.metadata.SCMDBDefinition) DatanodeSchemaTwoDBDefinition(org.apache.hadoop.ozone.container.metadata.DatanodeSchemaTwoDBDefinition) ReconDBDefinition(org.apache.hadoop.ozone.recon.spi.impl.ReconDBDefinition) DBDefinition(org.apache.hadoop.hdds.utils.db.DBDefinition) OMDBDefinition(org.apache.hadoop.ozone.om.codec.OMDBDefinition) OMDBDefinition(org.apache.hadoop.ozone.om.codec.OMDBDefinition) DatanodeSchemaTwoDBDefinition(org.apache.hadoop.ozone.container.metadata.DatanodeSchemaTwoDBDefinition) ReconSCMDBDefinition(org.apache.hadoop.ozone.recon.scm.ReconSCMDBDefinition) SCMDBDefinition(org.apache.hadoop.hdds.scm.metadata.SCMDBDefinition) ReconSCMDBDefinition(org.apache.hadoop.ozone.recon.scm.ReconSCMDBDefinition) ReconDBDefinition(org.apache.hadoop.ozone.recon.spi.impl.ReconDBDefinition) DatanodeSchemaOneDBDefinition(org.apache.hadoop.ozone.container.metadata.DatanodeSchemaOneDBDefinition) Test(org.junit.Test)

Example 2 with OMDBDefinition

use of org.apache.hadoop.ozone.om.codec.OMDBDefinition in project ozone by apache.

the class OzoneManagerDoubleBuffer method addCleanupEntry.

private void addCleanupEntry(DoubleBufferEntry entry, Map<String, List<Long>> cleanupEpochs) {
    Class<? extends OMClientResponse> responseClass = entry.getResponse().getClass();
    CleanupTableInfo cleanupTableInfo = responseClass.getAnnotation(CleanupTableInfo.class);
    if (cleanupTableInfo != null) {
        String[] cleanupTables;
        if (cleanupTableInfo.cleanupAll()) {
            cleanupTables = Arrays.stream(new OMDBDefinition().getColumnFamilies()).map(DBColumnFamilyDefinition::getTableName).toArray(String[]::new);
        } else {
            cleanupTables = cleanupTableInfo.cleanupTables();
        }
        for (String table : cleanupTables) {
            cleanupEpochs.computeIfAbsent(table, list -> new ArrayList<>()).add(entry.getTrxLogIndex());
        }
    } else {
        // add CleanupTableInfo annotation.
        throw new RuntimeException("CleanupTableInfo Annotation is missing " + "for" + responseClass);
    }
}
Also used : TransactionInfo(org.apache.hadoop.hdds.utils.TransactionInfo) Arrays(java.util.Arrays) TRANSACTION_INFO_KEY(org.apache.hadoop.ozone.OzoneConsts.TRANSACTION_INFO_KEY) LoggerFactory(org.slf4j.LoggerFactory) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) CleanupTableInfo(org.apache.hadoop.ozone.om.response.CleanupTableInfo) AtomicReference(java.util.concurrent.atomic.AtomicReference) Function(java.util.function.Function) ArrayList(java.util.ArrayList) OMClientResponse(org.apache.hadoop.ozone.om.response.OMClientResponse) Map(java.util.Map) OMResponse(org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMResponse) BatchOperation(org.apache.hadoop.hdds.utils.db.BatchOperation) Logger(org.slf4j.Logger) DoubleBufferEntry(org.apache.hadoop.ozone.om.ratis.helpers.DoubleBufferEntry) IOException(java.io.IOException) SupplierWithIOException(org.apache.hadoop.hdds.function.SupplierWithIOException) OMDBDefinition(org.apache.hadoop.ozone.om.codec.OMDBDefinition) Collectors(java.util.stream.Collectors) Daemon(org.apache.hadoop.util.Daemon) AtomicLong(java.util.concurrent.atomic.AtomicLong) List(java.util.List) TracingUtil(org.apache.hadoop.hdds.tracing.TracingUtil) ExitUtils(org.apache.ratis.util.ExitUtils) DBColumnFamilyDefinition(org.apache.hadoop.hdds.utils.db.DBColumnFamilyDefinition) Time(org.apache.hadoop.util.Time) Preconditions(com.google.common.base.Preconditions) Queue(java.util.Queue) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Collections(java.util.Collections) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) OMMetadataManager(org.apache.hadoop.ozone.om.OMMetadataManager) OzoneManagerDoubleBufferMetrics(org.apache.hadoop.ozone.om.ratis.metrics.OzoneManagerDoubleBufferMetrics) OMDBDefinition(org.apache.hadoop.ozone.om.codec.OMDBDefinition) DBColumnFamilyDefinition(org.apache.hadoop.hdds.utils.db.DBColumnFamilyDefinition) ArrayList(java.util.ArrayList) CleanupTableInfo(org.apache.hadoop.ozone.om.response.CleanupTableInfo)

Example 3 with OMDBDefinition

use of org.apache.hadoop.ozone.om.codec.OMDBDefinition in project ozone by apache.

the class TestOMDBDefinition method testDBDefinition.

@Test
public void testDBDefinition() throws Exception {
    OzoneConfiguration configuration = new OzoneConfiguration();
    File metaDir = folder.getRoot();
    DBStore store = OmMetadataManagerImpl.loadDB(configuration, metaDir);
    OMDBDefinition dbDef = new OMDBDefinition();
    // Get list of tables from DB Definitions
    DBColumnFamilyDefinition[] columnFamilyDefinitions = dbDef.getColumnFamilies();
    int countOmDefTables = columnFamilyDefinitions.length;
    ArrayList<String> missingDBDefTables = new ArrayList<>();
    // Get list of tables from the RocksDB Store
    Collection<String> missingOmDBTables = store.getTableNames().values();
    missingOmDBTables.remove("default");
    int countOmDBTables = missingOmDBTables.size();
    // Remove the file if it is found in both the datastructures
    for (DBColumnFamilyDefinition definition : columnFamilyDefinitions) {
        if (!missingOmDBTables.remove(definition.getName())) {
            missingDBDefTables.add(definition.getName());
        }
    }
    Assert.assertEquals("Tables in OmMetadataManagerImpl are:" + missingDBDefTables, 0, missingDBDefTables.size());
    Assert.assertEquals("Tables missing in OMDBDefinition are:" + missingOmDBTables, 0, missingOmDBTables.size());
    Assert.assertEquals(countOmDBTables, countOmDefTables);
}
Also used : OMDBDefinition(org.apache.hadoop.ozone.om.codec.OMDBDefinition) DBColumnFamilyDefinition(org.apache.hadoop.hdds.utils.db.DBColumnFamilyDefinition) ArrayList(java.util.ArrayList) OzoneConfiguration(org.apache.hadoop.hdds.conf.OzoneConfiguration) DBStore(org.apache.hadoop.hdds.utils.db.DBStore) File(java.io.File) Test(org.junit.Test)

Aggregations

OMDBDefinition (org.apache.hadoop.ozone.om.codec.OMDBDefinition)3 ArrayList (java.util.ArrayList)2 DBColumnFamilyDefinition (org.apache.hadoop.hdds.utils.db.DBColumnFamilyDefinition)2 Test (org.junit.Test)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Preconditions (com.google.common.base.Preconditions)1 File (java.io.File)1 IOException (java.io.IOException)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Queue (java.util.Queue)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 ConcurrentLinkedQueue (java.util.concurrent.ConcurrentLinkedQueue)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 Function (java.util.function.Function)1