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);
}
Aggregations