Search in sources :

Example 1 with OzoneManagerSyncMetrics

use of org.apache.hadoop.ozone.recon.metrics.OzoneManagerSyncMetrics in project ozone by apache.

the class TestReconWithOzoneManager method testOmDBSyncing.

@Test
public void testOmDBSyncing() throws Exception {
    // add a vol, bucket and key
    addKeys(0, 1);
    // check if OM metadata has vol0/bucket0/key0 info
    String ozoneKey = metadataManager.getOzoneKey("vol0", "bucket0", "key0");
    OmKeyInfo keyInfo1 = metadataManager.getKeyTable(getBucketLayout()).get(ozoneKey);
    TableIterator<String, ? extends Table.KeyValue<String, OmKeyInfo>> omKeyValueTableIterator = metadataManager.getKeyTable(getBucketLayout()).iterator();
    long omMetadataKeyCount = getTableKeyCount(omKeyValueTableIterator);
    // verify if OM has /vol0/bucket0/key0
    Assert.assertEquals("vol0", keyInfo1.getVolumeName());
    Assert.assertEquals("bucket0", keyInfo1.getBucketName());
    OzoneManagerServiceProviderImpl impl = (OzoneManagerServiceProviderImpl) cluster.getReconServer().getOzoneManagerServiceProvider();
    impl.syncDataFromOM();
    OzoneManagerSyncMetrics metrics = impl.getMetrics();
    // HTTP call to /api/containers
    String containerResponse = makeHttpCall(containerKeyServiceURL);
    long reconMetadataContainerCount = getReconContainerCount(containerResponse);
    // verify count of keys after full snapshot
    Assert.assertEquals(omMetadataKeyCount, reconMetadataContainerCount);
    // verify if Recon Metadata captures vol0/bucket0/key0 info in container0
    LinkedTreeMap containerResponseMap = getContainerResponseMap(containerResponse, 0);
    Assert.assertEquals(0, (long) (double) containerResponseMap.get("ContainerID"));
    Assert.assertEquals(1, (long) (double) containerResponseMap.get("NumberOfKeys"));
    // HTTP call to /api/task/status
    long omLatestSeqNumber = ((RDBStore) metadataManager.getStore()).getDb().getLatestSequenceNumber();
    String taskStatusResponse = makeHttpCall(taskStatusURL);
    long reconLatestSeqNumber = getReconTaskAttributeFromJson(taskStatusResponse, OmSnapshotRequest.name(), "lastUpdatedSeqNumber");
    // verify sequence number after full snapshot
    Assert.assertEquals(omLatestSeqNumber, reconLatestSeqNumber);
    Assert.assertEquals(0, metrics.getSequenceNumberLag().value());
    // add 4 keys to check for delta updates
    addKeys(1, 5);
    omKeyValueTableIterator = metadataManager.getKeyTable(getBucketLayout()).iterator();
    omMetadataKeyCount = getTableKeyCount(omKeyValueTableIterator);
    // update the next snapshot from om to verify delta updates
    impl.syncDataFromOM();
    // HTTP call to /api/containers
    containerResponse = makeHttpCall(containerKeyServiceURL);
    reconMetadataContainerCount = getReconContainerCount(containerResponse);
    // verify count of keys
    Assert.assertEquals(omMetadataKeyCount, reconMetadataContainerCount);
    // verify if Recon Metadata captures vol3/bucket3/key3 info in container3
    containerResponseMap = getContainerResponseMap(containerResponse, 3);
    Assert.assertEquals(3, (long) (double) containerResponseMap.get("ContainerID"));
    Assert.assertEquals(1, (long) (double) containerResponseMap.get("NumberOfKeys"));
    // HTTP call to /api/task/status
    omLatestSeqNumber = ((RDBStore) metadataManager.getStore()).getDb().getLatestSequenceNumber();
    taskStatusResponse = makeHttpCall(taskStatusURL);
    reconLatestSeqNumber = getReconTaskAttributeFromJson(taskStatusResponse, OmDeltaRequest.name(), "lastUpdatedSeqNumber");
    // verify sequence number after Delta Updates
    Assert.assertEquals(omLatestSeqNumber, reconLatestSeqNumber);
    Assert.assertEquals(0, metrics.getSequenceNumberLag().value());
    long beforeRestartSnapShotTimeStamp = getReconTaskAttributeFromJson(taskStatusResponse, OmSnapshotRequest.name(), "lastUpdatedTimestamp");
    // restart Recon
    cluster.restartReconServer();
    impl = (OzoneManagerServiceProviderImpl) cluster.getReconServer().getOzoneManagerServiceProvider();
    // add 5 more keys to OM
    addKeys(5, 10);
    omKeyValueTableIterator = metadataManager.getKeyTable(getBucketLayout()).iterator();
    omMetadataKeyCount = getTableKeyCount(omKeyValueTableIterator);
    // get the next snapshot from om
    impl.syncDataFromOM();
    // HTTP call to /api/containers
    containerResponse = makeHttpCall(containerKeyServiceURL);
    reconMetadataContainerCount = getReconContainerCount(containerResponse);
    // verify count of keys
    Assert.assertEquals(omMetadataKeyCount, reconMetadataContainerCount);
    // verify if Recon Metadata captures vol7/bucket7/key7 info in container7
    containerResponseMap = getContainerResponseMap(containerResponse, 7);
    Assert.assertEquals(7, (long) (double) containerResponseMap.get("ContainerID"));
    Assert.assertEquals(1, (long) (double) containerResponseMap.get("NumberOfKeys"));
    // HTTP call to /api/task/status
    omLatestSeqNumber = ((RDBStore) metadataManager.getStore()).getDb().getLatestSequenceNumber();
    taskStatusResponse = makeHttpCall(taskStatusURL);
    reconLatestSeqNumber = getReconTaskAttributeFromJson(taskStatusResponse, OmDeltaRequest.name(), "lastUpdatedSeqNumber");
    long afterRestartSnapShotTimeStamp = getReconTaskAttributeFromJson(taskStatusResponse, OmSnapshotRequest.name(), "lastUpdatedTimestamp");
    // verify only Delta updates were added to recon after restart.
    Assert.assertEquals(beforeRestartSnapShotTimeStamp, afterRestartSnapShotTimeStamp);
    // verify sequence number after Delta Updates
    Assert.assertEquals(omLatestSeqNumber, reconLatestSeqNumber);
    Assert.assertEquals(0, metrics.getSequenceNumberLag().value());
}
Also used : Table(org.apache.hadoop.hdds.utils.db.Table) LinkedTreeMap(com.google.gson.internal.LinkedTreeMap) OzoneManagerSyncMetrics(org.apache.hadoop.ozone.recon.metrics.OzoneManagerSyncMetrics) OmKeyInfo(org.apache.hadoop.ozone.om.helpers.OmKeyInfo) OzoneManagerServiceProviderImpl(org.apache.hadoop.ozone.recon.spi.impl.OzoneManagerServiceProviderImpl) RDBStore(org.apache.hadoop.hdds.utils.db.RDBStore) Test(org.junit.Test)

Example 2 with OzoneManagerSyncMetrics

use of org.apache.hadoop.ozone.recon.metrics.OzoneManagerSyncMetrics in project ozone by apache.

the class MockOzoneServiceProvider method testGetAndApplyDeltaUpdatesFromOM.

@Test
public void testGetAndApplyDeltaUpdatesFromOM() throws Exception {
    // Writing 2 Keys into a source OM DB and collecting it in a
    // DBUpdatesWrapper.
    OMMetadataManager sourceOMMetadataMgr = initializeNewOmMetadataManager(temporaryFolder.newFolder());
    writeDataToOm(sourceOMMetadataMgr, "key_one");
    writeDataToOm(sourceOMMetadataMgr, "key_two");
    RocksDB rocksDB = ((RDBStore) sourceOMMetadataMgr.getStore()).getDb();
    TransactionLogIterator transactionLogIterator = rocksDB.getUpdatesSince(0L);
    DBUpdates dbUpdatesWrapper = new DBUpdates();
    while (transactionLogIterator.isValid()) {
        TransactionLogIterator.BatchResult result = transactionLogIterator.getBatch();
        result.writeBatch().markWalTerminationPoint();
        WriteBatch writeBatch = result.writeBatch();
        dbUpdatesWrapper.addWriteBatch(writeBatch.data(), result.sequenceNumber());
        transactionLogIterator.next();
    }
    // OM Service Provider's Metadata Manager.
    OMMetadataManager omMetadataManager = initializeNewOmMetadataManager(temporaryFolder.newFolder());
    OzoneManagerServiceProviderImpl ozoneManagerServiceProvider = new OzoneManagerServiceProviderImpl(configuration, getTestReconOmMetadataManager(omMetadataManager, temporaryFolder.newFolder()), getMockTaskController(), new ReconUtils(), getMockOzoneManagerClient(dbUpdatesWrapper));
    OMDBUpdatesHandler updatesHandler = new OMDBUpdatesHandler(omMetadataManager);
    ozoneManagerServiceProvider.getAndApplyDeltaUpdatesFromOM(0L, updatesHandler);
    OzoneManagerSyncMetrics metrics = ozoneManagerServiceProvider.getMetrics();
    assertEquals(4.0, metrics.getAverageNumUpdatesInDeltaRequest().value(), 0.0);
    assertEquals(1, metrics.getNumNonZeroDeltaRequests().value());
    // In this method, we have to assert the "GET" path and the "APPLY" path.
    // Assert GET path --> verify if the OMDBUpdatesHandler picked up the 4
    // events ( 1 Vol PUT + 1 Bucket PUT + 2 Key PUTs).
    assertEquals(4, updatesHandler.getEvents().size());
    // Assert APPLY path --> Verify if the OM service provider's RocksDB got
    // the changes.
    String fullKey = omMetadataManager.getOzoneKey("sampleVol", "bucketOne", "key_one");
    assertTrue(ozoneManagerServiceProvider.getOMMetadataManagerInstance().getKeyTable(getBucketLayout()).isExist(fullKey));
    fullKey = omMetadataManager.getOzoneKey("sampleVol", "bucketOne", "key_two");
    assertTrue(ozoneManagerServiceProvider.getOMMetadataManagerInstance().getKeyTable(getBucketLayout()).isExist(fullKey));
}
Also used : RocksDB(org.rocksdb.RocksDB) ReconUtils(org.apache.hadoop.ozone.recon.ReconUtils) DBUpdates(org.apache.hadoop.ozone.om.helpers.DBUpdates) OzoneManagerSyncMetrics(org.apache.hadoop.ozone.recon.metrics.OzoneManagerSyncMetrics) ReconOMMetadataManager(org.apache.hadoop.ozone.recon.recovery.ReconOMMetadataManager) OMMetadataManager(org.apache.hadoop.ozone.om.OMMetadataManager) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) WriteBatch(org.rocksdb.WriteBatch) RDBStore(org.apache.hadoop.hdds.utils.db.RDBStore) TransactionLogIterator(org.rocksdb.TransactionLogIterator) OMDBUpdatesHandler(org.apache.hadoop.ozone.recon.tasks.OMDBUpdatesHandler) Test(org.junit.Test)

Example 3 with OzoneManagerSyncMetrics

use of org.apache.hadoop.ozone.recon.metrics.OzoneManagerSyncMetrics in project ozone by apache.

the class MockOzoneServiceProvider method testSyncDataFromOMFullSnapshot.

@Test
public void testSyncDataFromOMFullSnapshot() throws Exception {
    // Empty OM DB to start with.
    ReconOMMetadataManager omMetadataManager = getTestReconOmMetadataManager(initializeEmptyOmMetadataManager(temporaryFolder.newFolder()), temporaryFolder.newFolder());
    ReconTaskStatusDao reconTaskStatusDaoMock = mock(ReconTaskStatusDao.class);
    doNothing().when(reconTaskStatusDaoMock).update(any(ReconTaskStatus.class));
    ReconTaskController reconTaskControllerMock = getMockTaskController();
    when(reconTaskControllerMock.getReconTaskStatusDao()).thenReturn(reconTaskStatusDaoMock);
    doNothing().when(reconTaskControllerMock).reInitializeTasks(omMetadataManager);
    OzoneManagerServiceProviderImpl ozoneManagerServiceProvider = new MockOzoneServiceProvider(configuration, omMetadataManager, reconTaskControllerMock, new ReconUtils(), ozoneManagerProtocol);
    OzoneManagerSyncMetrics metrics = ozoneManagerServiceProvider.getMetrics();
    assertEquals(0, metrics.getNumSnapshotRequests().value());
    // Should trigger full snapshot request.
    ozoneManagerServiceProvider.syncDataFromOM();
    ArgumentCaptor<ReconTaskStatus> captor = ArgumentCaptor.forClass(ReconTaskStatus.class);
    verify(reconTaskStatusDaoMock, times(1)).update(captor.capture());
    assertTrue(captor.getValue().getTaskName().equals(OmSnapshotRequest.name()));
    verify(reconTaskControllerMock, times(1)).reInitializeTasks(omMetadataManager);
    assertEquals(1, metrics.getNumSnapshotRequests().value());
}
Also used : ReconUtils(org.apache.hadoop.ozone.recon.ReconUtils) OzoneManagerSyncMetrics(org.apache.hadoop.ozone.recon.metrics.OzoneManagerSyncMetrics) ReconTaskController(org.apache.hadoop.ozone.recon.tasks.ReconTaskController) ReconOMMetadataManager(org.apache.hadoop.ozone.recon.recovery.ReconOMMetadataManager) ReconTaskStatusDao(org.hadoop.ozone.recon.schema.tables.daos.ReconTaskStatusDao) ReconTaskStatus(org.hadoop.ozone.recon.schema.tables.pojos.ReconTaskStatus) Test(org.junit.Test)

Example 4 with OzoneManagerSyncMetrics

use of org.apache.hadoop.ozone.recon.metrics.OzoneManagerSyncMetrics in project ozone by apache.

the class MockOzoneServiceProvider method testGetAndApplyDeltaUpdatesFromOMWithLimit.

@Test
public void testGetAndApplyDeltaUpdatesFromOMWithLimit() throws Exception {
    // Writing 2 Keys into a source OM DB and collecting it in a
    // DBUpdatesWrapper.
    OMMetadataManager sourceOMMetadataMgr = initializeNewOmMetadataManager(temporaryFolder.newFolder());
    writeDataToOm(sourceOMMetadataMgr, "key_one");
    writeDataToOm(sourceOMMetadataMgr, "key_two");
    RocksDB rocksDB = ((RDBStore) sourceOMMetadataMgr.getStore()).getDb();
    TransactionLogIterator transactionLogIterator = rocksDB.getUpdatesSince(0L);
    DBUpdates[] dbUpdatesWrapper = new DBUpdates[4];
    int index = 0;
    while (transactionLogIterator.isValid()) {
        TransactionLogIterator.BatchResult result = transactionLogIterator.getBatch();
        result.writeBatch().markWalTerminationPoint();
        WriteBatch writeBatch = result.writeBatch();
        dbUpdatesWrapper[index] = new DBUpdates();
        dbUpdatesWrapper[index].addWriteBatch(writeBatch.data(), result.sequenceNumber());
        index++;
        transactionLogIterator.next();
    }
    // OM Service Provider's Metadata Manager.
    OMMetadataManager omMetadataManager = initializeNewOmMetadataManager(temporaryFolder.newFolder());
    OzoneConfiguration withLimitConfiguration = new OzoneConfiguration(configuration);
    withLimitConfiguration.setLong(RECON_OM_DELTA_UPDATE_LIMIT, 1);
    withLimitConfiguration.setLong(RECON_OM_DELTA_UPDATE_LOOP_LIMIT, 3);
    OzoneManagerServiceProviderImpl ozoneManagerServiceProvider = new OzoneManagerServiceProviderImpl(withLimitConfiguration, getTestReconOmMetadataManager(omMetadataManager, temporaryFolder.newFolder()), getMockTaskController(), new ReconUtils(), getMockOzoneManagerClientWith4Updates(dbUpdatesWrapper[0], dbUpdatesWrapper[1], dbUpdatesWrapper[2], dbUpdatesWrapper[3]));
    OMDBUpdatesHandler updatesHandler = new OMDBUpdatesHandler(omMetadataManager);
    ozoneManagerServiceProvider.getAndApplyDeltaUpdatesFromOM(0L, updatesHandler);
    OzoneManagerSyncMetrics metrics = ozoneManagerServiceProvider.getMetrics();
    assertEquals(1.0, metrics.getAverageNumUpdatesInDeltaRequest().value(), 0.0);
    assertEquals(3, metrics.getNumNonZeroDeltaRequests().value());
    // In this method, we have to assert the "GET" path and the "APPLY" path.
    // Assert GET path --> verify if the OMDBUpdatesHandler picked up the first
    // 3 of 4 events ( 1 Vol PUT + 1 Bucket PUT + 2 Key PUTs).
    assertEquals(3, updatesHandler.getEvents().size());
    // Assert APPLY path --> Verify if the OM service provider's RocksDB got
    // the first 3 changes, last change not applied.
    String fullKey = omMetadataManager.getOzoneKey("sampleVol", "bucketOne", "key_one");
    assertTrue(ozoneManagerServiceProvider.getOMMetadataManagerInstance().getKeyTable(getBucketLayout()).isExist(fullKey));
    fullKey = omMetadataManager.getOzoneKey("sampleVol", "bucketOne", "key_two");
    assertFalse(ozoneManagerServiceProvider.getOMMetadataManagerInstance().getKeyTable(getBucketLayout()).isExist(fullKey));
}
Also used : RocksDB(org.rocksdb.RocksDB) ReconUtils(org.apache.hadoop.ozone.recon.ReconUtils) OzoneConfiguration(org.apache.hadoop.hdds.conf.OzoneConfiguration) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) TransactionLogIterator(org.rocksdb.TransactionLogIterator) DBCheckpoint(org.apache.hadoop.hdds.utils.db.DBCheckpoint) DBUpdates(org.apache.hadoop.ozone.om.helpers.DBUpdates) OzoneManagerSyncMetrics(org.apache.hadoop.ozone.recon.metrics.OzoneManagerSyncMetrics) ReconOMMetadataManager(org.apache.hadoop.ozone.recon.recovery.ReconOMMetadataManager) OMMetadataManager(org.apache.hadoop.ozone.om.OMMetadataManager) WriteBatch(org.rocksdb.WriteBatch) RDBStore(org.apache.hadoop.hdds.utils.db.RDBStore) OMDBUpdatesHandler(org.apache.hadoop.ozone.recon.tasks.OMDBUpdatesHandler) Test(org.junit.Test)

Example 5 with OzoneManagerSyncMetrics

use of org.apache.hadoop.ozone.recon.metrics.OzoneManagerSyncMetrics in project ozone by apache.

the class MockOzoneServiceProvider method testSyncDataFromOMDeltaUpdates.

@Test
public void testSyncDataFromOMDeltaUpdates() throws Exception {
    // Non-Empty OM DB to start with.
    ReconOMMetadataManager omMetadataManager = getTestReconOmMetadataManager(initializeNewOmMetadataManager(temporaryFolder.newFolder()), temporaryFolder.newFolder());
    ReconTaskStatusDao reconTaskStatusDaoMock = mock(ReconTaskStatusDao.class);
    doNothing().when(reconTaskStatusDaoMock).update(any(ReconTaskStatus.class));
    ReconTaskController reconTaskControllerMock = getMockTaskController();
    when(reconTaskControllerMock.getReconTaskStatusDao()).thenReturn(reconTaskStatusDaoMock);
    doNothing().when(reconTaskControllerMock).consumeOMEvents(any(OMUpdateEventBatch.class), any(OMMetadataManager.class));
    OzoneManagerServiceProviderImpl ozoneManagerServiceProvider = new OzoneManagerServiceProviderImpl(configuration, omMetadataManager, reconTaskControllerMock, new ReconUtils(), ozoneManagerProtocol);
    OzoneManagerSyncMetrics metrics = ozoneManagerServiceProvider.getMetrics();
    // Should trigger delta updates.
    ozoneManagerServiceProvider.syncDataFromOM();
    ArgumentCaptor<ReconTaskStatus> captor = ArgumentCaptor.forClass(ReconTaskStatus.class);
    verify(reconTaskStatusDaoMock, times(1)).update(captor.capture());
    assertTrue(captor.getValue().getTaskName().equals(OmDeltaRequest.name()));
    verify(reconTaskControllerMock, times(1)).consumeOMEvents(any(OMUpdateEventBatch.class), any(OMMetadataManager.class));
    assertEquals(0, metrics.getNumSnapshotRequests().value());
}
Also used : ReconUtils(org.apache.hadoop.ozone.recon.ReconUtils) OzoneManagerSyncMetrics(org.apache.hadoop.ozone.recon.metrics.OzoneManagerSyncMetrics) ReconOMMetadataManager(org.apache.hadoop.ozone.recon.recovery.ReconOMMetadataManager) OMMetadataManager(org.apache.hadoop.ozone.om.OMMetadataManager) ReconTaskController(org.apache.hadoop.ozone.recon.tasks.ReconTaskController) ReconOMMetadataManager(org.apache.hadoop.ozone.recon.recovery.ReconOMMetadataManager) ReconTaskStatusDao(org.hadoop.ozone.recon.schema.tables.daos.ReconTaskStatusDao) ReconTaskStatus(org.hadoop.ozone.recon.schema.tables.pojos.ReconTaskStatus) OMUpdateEventBatch(org.apache.hadoop.ozone.recon.tasks.OMUpdateEventBatch) Test(org.junit.Test)

Aggregations

OzoneManagerSyncMetrics (org.apache.hadoop.ozone.recon.metrics.OzoneManagerSyncMetrics)5 Test (org.junit.Test)5 ReconUtils (org.apache.hadoop.ozone.recon.ReconUtils)4 ReconOMMetadataManager (org.apache.hadoop.ozone.recon.recovery.ReconOMMetadataManager)4 RDBStore (org.apache.hadoop.hdds.utils.db.RDBStore)3 OMMetadataManager (org.apache.hadoop.ozone.om.OMMetadataManager)3 DBUpdates (org.apache.hadoop.ozone.om.helpers.DBUpdates)2 OMDBUpdatesHandler (org.apache.hadoop.ozone.recon.tasks.OMDBUpdatesHandler)2 ReconTaskController (org.apache.hadoop.ozone.recon.tasks.ReconTaskController)2 ReconTaskStatusDao (org.hadoop.ozone.recon.schema.tables.daos.ReconTaskStatusDao)2 ReconTaskStatus (org.hadoop.ozone.recon.schema.tables.pojos.ReconTaskStatus)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2 RocksDB (org.rocksdb.RocksDB)2 TransactionLogIterator (org.rocksdb.TransactionLogIterator)2 WriteBatch (org.rocksdb.WriteBatch)2 LinkedTreeMap (com.google.gson.internal.LinkedTreeMap)1 OzoneConfiguration (org.apache.hadoop.hdds.conf.OzoneConfiguration)1 DBCheckpoint (org.apache.hadoop.hdds.utils.db.DBCheckpoint)1 Table (org.apache.hadoop.hdds.utils.db.Table)1 OmKeyInfo (org.apache.hadoop.ozone.om.helpers.OmKeyInfo)1