sumitagrawl commented on code in PR #8845:
URL: https://github.com/apache/ozone/pull/8845#discussion_r2256530562
##########
hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/block/SCMDeletedBlockTransactionStatusManager.java:
##########
@@ -563,4 +682,91 @@ private boolean
isTransactionFailed(DeleteBlockTransactionResult result) {
public int getTransactionToDNsCommitMapSize() {
return transactionToDNsCommitMap.size();
}
+
+ public void reinitialize(Table<String, ByteString> configTable) throws
IOException {
+ // DB onFlush() will be called before reinitialization.
+ this.statefulConfigTable = configTable;
+ this.initDataDistributionData();
+ }
+
+ @VisibleForTesting
+ public Map<Long, TxBlockInfo> getTxSizeMap() {
+ return txSizeMap;
+ }
+
+ @VisibleForTesting
+ public static void setDisableDataDistributionForTest(boolean disabled) {
+ disableDataDistributionForTest = disabled;
+ }
+
+ public DeletedBlocksTransactionSummary getTransactionSummary() {
+ return DeletedBlocksTransactionSummary.newBuilder()
+ .setFirstTxID(firstTxIdForDataDistribution)
+ .setTotalTransactionCount(totalTxCount.get())
+ .setTotalBlockCount(totalBlockCount.get())
+ .setTotalBlockSize(totalBlocksSize.get())
+ .setTotalBlockReplicatedSize(totalReplicatedBlocksSize.get())
+ .build();
+ }
+
+ private void initDataDistributionData() throws IOException {
+ if
(VersionedDatanodeFeatures.isFinalized(HDDSLayoutFeature.DATA_DISTRIBUTION)) {
+ DeletedBlocksTransactionSummary summary = loadDeletedBlocksSummary();
+ if (summary != null) {
+ firstTxIdForDataDistribution = summary.getFirstTxID();
Review Comment:
isFirstTxIdForDataDistributionSet is not set, but
firstTxIdForDataDistribution is set from db. Do this is correct ? as during
restart after finalize and summary already contains firstTxId.
##########
hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/block/ScmBlockDeletingServiceMetrics.java:
##########
@@ -272,6 +315,19 @@ public void getMetrics(MetricsCollector metricsCollector,
boolean all) {
.addGauge(DatanodeCommandDetails.BLOCKS_SENT_TO_DN_COMMAND,
e.getValue().getBlocksSent());
}
+
+ // add metrics for deleted block transaction summary
+ if (blockManager.getDeletedBlockLog().isTransactionSummarySupported()) {
Review Comment:
can move other metrics to flag -- numBlockDeletionTransactionSizeFromCache
and numBlockDeletionTransactionSizeFromDB to be consistent for the feature
##########
hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/block/SCMDeletedBlockTransactionStatusManager.java:
##########
@@ -441,6 +475,67 @@ private boolean alreadyExecuted(DatanodeID dnId, long
txId) {
.contains(dnId);
}
+ @VisibleForTesting
+ public void addTransactions(ArrayList<DeletedBlocksTransaction> txList)
throws IOException {
+ if (txList.isEmpty()) {
+ return;
+ }
+ if
(VersionedDatanodeFeatures.isFinalized(HDDSLayoutFeature.DATA_DISTRIBUTION) &&
+ txList.get(0).hasTotalBlockSize() && !disableDataDistributionForTest) {
+ if (!isFirstTxIdForDataDistributionSet) {
+ // set the first transaction ID for data distribution
+ isFirstTxIdForDataDistributionSet = true;
+ firstTxIdForDataDistribution = txList.get(0).getTxID();
+ }
+ txList.stream().filter(t -> t.hasTotalBlockSize()).forEach(t ->
incrDeletedBlocksSummary(t));
+ deletedBlockLogStateManager.addTransactionsToDB(txList, getSummary());
+ return;
+ }
+ deletedBlockLogStateManager.addTransactionsToDB(txList);
+ }
+
+ private void incrDeletedBlocksSummary(DeletedBlocksTransaction tx) {
+ totalTxCount.addAndGet(1);
+ totalBlockCount.addAndGet(tx.getLocalIDCount());
+ totalBlocksSize.addAndGet(tx.getTotalBlockSize());
+ totalReplicatedBlocksSize.addAndGet(tx.getTotalBlockReplicatedSize());
+ }
+
+ @VisibleForTesting
+ public void removeTransactions(ArrayList<Long> txIDs) throws IOException {
+ if (txIDs.isEmpty()) {
+ return;
+ }
+ if
(VersionedDatanodeFeatures.isFinalized(HDDSLayoutFeature.DATA_DISTRIBUTION) &&
+ !disableDataDistributionForTest) {
+ ArrayList<Long> txToQueryList = new ArrayList<>();
+ for (Long txID: txIDs) {
+ TxBlockInfo txBlockInfo = txSizeMap.remove(txID);
+ if (txBlockInfo != null) {
+ // txBlockInfosToBeDeleted.add(txBlockInfo);
+ descDeletedBlocksSummary(txBlockInfo);
+ metrics.incrBlockDeletionTransactionSizeFromCache();
+ } else {
+ // Fetch the transaction from DB to get the size. This happens during
+ // 1. SCM leader transfer, deletion command send by one SCM,
+ // while the deletion ack received by a different SCM
+ // 2. SCM restarts, txBlockInfoMap is empty, while receiving the
deletion ack from DN
+ txToQueryList.add(txID);
+ metrics.incrBlockDeletionTransactionSizeFromDB();
+ }
+ }
+ if (!txToQueryList.isEmpty()) {
+ ArrayList<DeletedBlocksTransaction> txList =
Review Comment:
Is it possible in retry to remove again? if so may reduce summary by twice
and make value in-consistent. May be need recheck if exist and then remove from
summary
##########
hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/block/SCMDeletedBlockTransactionStatusManager.java:
##########
@@ -441,6 +475,67 @@ private boolean alreadyExecuted(DatanodeID dnId, long
txId) {
.contains(dnId);
}
+ @VisibleForTesting
+ public void addTransactions(ArrayList<DeletedBlocksTransaction> txList)
throws IOException {
+ if (txList.isEmpty()) {
+ return;
+ }
+ if
(VersionedDatanodeFeatures.isFinalized(HDDSLayoutFeature.DATA_DISTRIBUTION) &&
+ txList.get(0).hasTotalBlockSize() && !disableDataDistributionForTest) {
+ if (!isFirstTxIdForDataDistributionSet) {
+ // set the first transaction ID for data distribution
+ isFirstTxIdForDataDistributionSet = true;
+ firstTxIdForDataDistribution = txList.get(0).getTxID();
+ }
+ txList.stream().filter(t -> t.hasTotalBlockSize()).forEach(t ->
incrDeletedBlocksSummary(t));
Review Comment:
we add block count, size to memory counter, but when it fails at DB
intermittently, can corrupt memory counter, we need revert the counter value.
Same case for removeTransactions().
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]