Search in sources :

Example 1 with OMUpdateEventBatch

use of org.apache.hadoop.ozone.recon.tasks.OMUpdateEventBatch in project ozone by apache.

the class OzoneManagerServiceProviderImpl method syncDataFromOM.

/**
 * Based on current state of Recon's OM DB, we either get delta updates or
 * full snapshot from Ozone Manager.
 */
@VisibleForTesting
public void syncDataFromOM() {
    LOG.info("Syncing data from Ozone Manager.");
    long currentSequenceNumber = getCurrentOMDBSequenceNumber();
    LOG.debug("Seq number of Recon's OM DB : {}", currentSequenceNumber);
    boolean fullSnapshot = false;
    if (currentSequenceNumber <= 0) {
        fullSnapshot = true;
    } else {
        try (OMDBUpdatesHandler omdbUpdatesHandler = new OMDBUpdatesHandler(omMetadataManager)) {
            LOG.info("Obtaining delta updates from Ozone Manager");
            // Get updates from OM and apply to local Recon OM DB.
            getAndApplyDeltaUpdatesFromOM(currentSequenceNumber, omdbUpdatesHandler);
            // Update timestamp of successful delta updates query.
            ReconTaskStatus reconTaskStatusRecord = new ReconTaskStatus(OmSnapshotTaskName.OmDeltaRequest.name(), System.currentTimeMillis(), getCurrentOMDBSequenceNumber());
            reconTaskStatusDao.update(reconTaskStatusRecord);
            // Pass on DB update events to tasks that are listening.
            reconTaskController.consumeOMEvents(new OMUpdateEventBatch(omdbUpdatesHandler.getEvents()), omMetadataManager);
        } catch (InterruptedException intEx) {
            Thread.currentThread().interrupt();
        } catch (Exception e) {
            metrics.incrNumDeltaRequestsFailed();
            LOG.warn("Unable to get and apply delta updates from OM.", e);
            fullSnapshot = true;
        }
    }
    if (fullSnapshot) {
        try {
            metrics.incrNumSnapshotRequests();
            LOG.info("Obtaining full snapshot from Ozone Manager");
            // Update local Recon OM DB to new snapshot.
            boolean success = updateReconOmDBWithNewSnapshot();
            // Update timestamp of successful delta updates query.
            if (success) {
                ReconTaskStatus reconTaskStatusRecord = new ReconTaskStatus(OmSnapshotTaskName.OmSnapshotRequest.name(), System.currentTimeMillis(), getCurrentOMDBSequenceNumber());
                reconTaskStatusDao.update(reconTaskStatusRecord);
                // Reinitialize tasks that are listening.
                LOG.info("Calling reprocess on Recon tasks.");
                reconTaskController.reInitializeTasks(omMetadataManager);
            }
        } catch (InterruptedException intEx) {
            Thread.currentThread().interrupt();
        } catch (Exception e) {
            metrics.incrNumSnapshotRequestsFailed();
            LOG.error("Unable to update Recon's metadata with new OM DB. ", e);
        }
    }
}
Also used : ReconTaskStatus(org.hadoop.ozone.recon.schema.tables.pojos.ReconTaskStatus) OMDBUpdatesHandler(org.apache.hadoop.ozone.recon.tasks.OMDBUpdatesHandler) RocksDBException(org.rocksdb.RocksDBException) IOException(java.io.IOException) OMUpdateEventBatch(org.apache.hadoop.ozone.recon.tasks.OMUpdateEventBatch) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 IOException (java.io.IOException)1 OMDBUpdatesHandler (org.apache.hadoop.ozone.recon.tasks.OMDBUpdatesHandler)1 OMUpdateEventBatch (org.apache.hadoop.ozone.recon.tasks.OMUpdateEventBatch)1 ReconTaskStatus (org.hadoop.ozone.recon.schema.tables.pojos.ReconTaskStatus)1 RocksDBException (org.rocksdb.RocksDBException)1