Search in sources :

Example 1 with RDBBatchOperation

use of org.apache.hadoop.hdds.utils.db.RDBBatchOperation in project ozone by apache.

the class OzoneManagerServiceProviderImpl method innerGetAndApplyDeltaUpdatesFromOM.

/**
 * Get Delta updates from OM through RPC call and apply to local OM DB as
 * well as accumulate in a buffer.
 * @param fromSequenceNumber from sequence number to request from.
 * @param omdbUpdatesHandler OM DB updates handler to buffer updates.
 * @throws IOException when OM RPC request fails.
 * @throws RocksDBException when writing to RocksDB fails.
 */
@VisibleForTesting
void innerGetAndApplyDeltaUpdatesFromOM(long fromSequenceNumber, OMDBUpdatesHandler omdbUpdatesHandler) throws IOException, RocksDBException {
    DBUpdatesRequest dbUpdatesRequest = DBUpdatesRequest.newBuilder().setSequenceNumber(fromSequenceNumber).setLimitCount(deltaUpdateLimit).build();
    DBUpdates dbUpdates = ozoneManagerClient.getDBUpdates(dbUpdatesRequest);
    int numUpdates = 0;
    long latestSequenceNumberOfOM = -1L;
    if (null != dbUpdates && dbUpdates.getCurrentSequenceNumber() != -1) {
        latestSequenceNumberOfOM = dbUpdates.getLatestSequenceNumber();
        RDBStore rocksDBStore = (RDBStore) omMetadataManager.getStore();
        final RocksDatabase rocksDB = rocksDBStore.getDb();
        numUpdates = dbUpdates.getData().size();
        if (numUpdates > 0) {
            metrics.incrNumUpdatesInDeltaTotal(numUpdates);
        }
        for (byte[] data : dbUpdates.getData()) {
            try (WriteBatch writeBatch = new WriteBatch(data)) {
                writeBatch.iterate(omdbUpdatesHandler);
                try (RDBBatchOperation rdbBatchOperation = new RDBBatchOperation(writeBatch)) {
                    try (WriteOptions wOpts = new WriteOptions()) {
                        rdbBatchOperation.commit(rocksDB, wOpts);
                    }
                }
            }
        }
    }
    long lag = latestSequenceNumberOfOM == -1 ? 0 : latestSequenceNumberOfOM - getCurrentOMDBSequenceNumber();
    metrics.setSequenceNumberLag(lag);
    LOG.info("Number of updates received from OM : {}, " + "SequenceNumber diff: {}, SequenceNumber Lag from OM {}.", numUpdates, getCurrentOMDBSequenceNumber() - fromSequenceNumber, lag);
}
Also used : WriteOptions(org.rocksdb.WriteOptions) RDBBatchOperation(org.apache.hadoop.hdds.utils.db.RDBBatchOperation) DBUpdates(org.apache.hadoop.ozone.om.helpers.DBUpdates) DBUpdatesRequest(org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.DBUpdatesRequest) RocksDatabase(org.apache.hadoop.hdds.utils.db.RocksDatabase) WriteBatch(org.rocksdb.WriteBatch) DBCheckpoint(org.apache.hadoop.hdds.utils.db.DBCheckpoint) RocksDBCheckpoint(org.apache.hadoop.hdds.utils.db.RocksDBCheckpoint) RDBStore(org.apache.hadoop.hdds.utils.db.RDBStore) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 DBCheckpoint (org.apache.hadoop.hdds.utils.db.DBCheckpoint)1 RDBBatchOperation (org.apache.hadoop.hdds.utils.db.RDBBatchOperation)1 RDBStore (org.apache.hadoop.hdds.utils.db.RDBStore)1 RocksDBCheckpoint (org.apache.hadoop.hdds.utils.db.RocksDBCheckpoint)1 RocksDatabase (org.apache.hadoop.hdds.utils.db.RocksDatabase)1 DBUpdates (org.apache.hadoop.ozone.om.helpers.DBUpdates)1 DBUpdatesRequest (org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.DBUpdatesRequest)1 WriteBatch (org.rocksdb.WriteBatch)1 WriteOptions (org.rocksdb.WriteOptions)1