Skip to content

Commit

Permalink
Fix incr to set, fail num
Browse files Browse the repository at this point in the history
  • Loading branch information
tejaskriya committed Nov 22, 2024
1 parent b9fea5d commit 4573baf
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,13 @@ public final class BlockDeletingServiceMetrics {
private MutableGaugeLong containerChosenCountInLastIteration;

@Metric(about = "Total number of successful delete blocks in latest iteration.")
private MutableCounterLong successCountInLastIteration;
private MutableGaugeLong successCountInLastIteration;

@Metric(about = "The total bytes for blocks successfully deleted in the latest iteration.")
private MutableCounterLong successBytesInLastIteration;
private MutableGaugeLong successBytesInLastIteration;

@Metric(about = "The number of failed delete blocks in the latest iteration.")
private MutableCounterLong failureCountInLastIteration;
private MutableGaugeLong failureCountInLastIteration;


private BlockDeletingServiceMetrics() {
Expand Down Expand Up @@ -131,8 +131,8 @@ public void incrSuccessBytes(long bytes) {
this.successBytes.incr(bytes);
}

public void incrFailureCount() {
this.failureCount.incr();
public void incrFailureCount(long delta) {
this.failureCount.incr(delta);
}

public void incrReceivedTransactionCount(long count) {
Expand Down Expand Up @@ -225,16 +225,24 @@ public void setContainerChosenCountInLastIteration(
this.containerChosenCountInLastIteration.set(containerChosenCountInLastIteration);
}

public void incrSuccessCountInLastIteration(long delta) {
this.successCountInLastIteration.incr(delta);
public void setSuccessCountInLastIteration(long delta) {
this.successCountInLastIteration.set(delta);
}

public void incrSuccessBytesInLastIteration(long delta) {
this.successBytesInLastIteration.incr(delta);
public void setSuccessBytesInLastIteration(long delta) {
this.successBytesInLastIteration.set(delta);
}

public void incrFailureCountInLastIteration(long delta) {
this.failureCountInLastIteration.incr(delta);
public void setFailureCountInLastIteration(long delta) {
this.failureCountInLastIteration.set(delta);
}

public long getBlockChosenCountInLastIteration() {
return blockChosenCountInLastIteration.value();
}

public long getContainerChosenCountInLastIteration() {
return containerChosenCountInLastIteration.value();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,9 @@ public BackgroundTaskQueue getTasks() {
metrics.setContainerChosenCountInLastIteration(containers.size());
metrics.incrTotalBlockChosenCount(totalBlocks);
metrics.incrTotalContainerChosenCount(containers.size());
metrics.incrSuccessCountInLastIteration(BlockDeletingTask.getSuccessBlockDeleteInLastIteration());
metrics.incrSuccessBytesInLastIteration(BlockDeletingTask.getSuccessBytesDeletedInLastIteration());
metrics.incrFailureCountInLastIteration(BlockDeletingTask.getFailBlockDeleteInLastIteration());
metrics.setSuccessCountInLastIteration(BlockDeletingTask.getSuccessBlockDeleteInLastIteration());
metrics.setSuccessBytesInLastIteration(BlockDeletingTask.getSuccessBytesDeletedInLastIteration());
metrics.setFailureCountInLastIteration(BlockDeletingTask.getFailBlockDeleteInLastIteration());
if (containers.size() > 0) {
LOG.debug("Queued {} blocks from {} containers for deletion",
totalBlocks, containers.size());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ public ContainerBackgroundTaskResult deleteViaSchema1(
if (!checkDataDir(dataDir)) {
return crr;
}
int toBeDeletedNum = 0, deletedBlocksCount = 0;
try {
Table<String, BlockData> blockDataTable =
meta.getStore().getBlockDataTable();
Expand All @@ -194,6 +195,7 @@ public ContainerBackgroundTaskResult deleteViaSchema1(
.getSequentialRangeKVs(containerData.startKeyEmpty(),
(int) blocksToDelete, containerData.containerPrefix(),
filter);
toBeDeletedNum = toDeleteBlocks.size();
if (toDeleteBlocks.isEmpty()) {
LOG.debug("No under deletion block found in container : {}",
containerData.getContainerID());
Expand All @@ -202,7 +204,7 @@ public ContainerBackgroundTaskResult deleteViaSchema1(

List<String> succeedBlocks = new LinkedList<>();
LOG.debug("Container : {}, To-Delete blocks : {}",
containerData.getContainerID(), toDeleteBlocks.size());
containerData.getContainerID(), toBeDeletedNum);

Handler handler = Objects.requireNonNull(ozoneContainer.getDispatcher()
.getHandler(container.getContainerType()));
Expand Down Expand Up @@ -242,7 +244,7 @@ public ContainerBackgroundTaskResult deleteViaSchema1(
// updated with decremented used bytes during deleteChunk. This is
// done here so that all the DB update for block delete can be
// batched together while committing to DB.
int deletedBlocksCount = succeedBlocks.size();
deletedBlocksCount = succeedBlocks.size();
containerData.updateAndCommitDBCounters(meta, batch,
deletedBlocksCount, releasedBytes);
// Once DB update is persisted, check if there are any blocks
Expand Down Expand Up @@ -275,8 +277,9 @@ public ContainerBackgroundTaskResult deleteViaSchema1(
} catch (IOException exception) {
LOG.warn("Deletion operation was not successful for container: " +
container.getContainerData().getContainerID(), exception);
metrics.incrFailureCount();
incrFailBlockDeleteInLastIteration(1);
int failed = toBeDeletedNum - deletedBlocksCount;
metrics.incrFailureCount(failed);
incrFailBlockDeleteInLastIteration(failed);
throw exception;
}
}
Expand Down Expand Up @@ -330,6 +333,7 @@ private ContainerBackgroundTaskResult deleteViaTransactionStore(
if (!checkDataDir(dataDir)) {
return crr;
}
int toBeDeletedNum = 0, deletedBlocksCount = 0;
try {
Table<String, BlockData> blockDataTable =
meta.getStore().getBlockDataTable();
Expand All @@ -346,6 +350,7 @@ private ContainerBackgroundTaskResult deleteViaTransactionStore(
numBlocks += delTx.getLocalIDList().size();
delBlocks.add(delTx);
}
toBeDeletedNum = delBlocks.size();
if (delBlocks.isEmpty()) {
LOG.info("No transaction found in container {} with pending delete " +
"block count {}",
Expand All @@ -360,15 +365,15 @@ private ContainerBackgroundTaskResult deleteViaTransactionStore(
}

LOG.debug("Container : {}, To-Delete blocks : {}",
containerData.getContainerID(), delBlocks.size());
containerData.getContainerID(), toBeDeletedNum);

Handler handler = Objects.requireNonNull(ozoneContainer.getDispatcher()
.getHandler(container.getContainerType()));

DeleteTransactionStats deleteBlocksResult =
deleteTransactions(delBlocks, handler, blockDataTable, container);
int deletedBlocksProcessed = deleteBlocksResult.getBlocksProcessed();
int deletedBlocksCount = deleteBlocksResult.getBlocksDeleted();
deletedBlocksCount = deleteBlocksResult.getBlocksDeleted();
long releasedBytes = deleteBlocksResult.getBytesReleased();
List<DeletedBlocksTransaction> deletedBlocksTxs =
deleteBlocksResult.deletedBlocksTxs();
Expand Down Expand Up @@ -426,8 +431,9 @@ private ContainerBackgroundTaskResult deleteViaTransactionStore(
} catch (IOException exception) {
LOG.warn("Deletion operation was not successful for container: " +
container.getContainerData().getContainerID(), exception);
metrics.incrFailureCount();
incrFailBlockDeleteInLastIteration(1);
int failed = toBeDeletedNum - deletedBlocksCount;
metrics.incrFailureCount(failed);
incrFailBlockDeleteInLastIteration(failed);
throw exception;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -604,9 +604,11 @@ public void testBlockDeletion(ContainerTestVersionInfo versionInfo)
assertEquals(2,
deletingServiceMetrics.getTotalBlockChosenCount()
- totalBlockChosenCount);
assertEquals(2, deletingServiceMetrics.getBlockChosenCountInLastIteration());
assertEquals(1,
deletingServiceMetrics.getTotalContainerChosenCount()
- totalContainerChosenCount);
assertEquals(1, deletingServiceMetrics.getContainerChosenCountInLastIteration());
// The value of the getTotalPendingBlockCount Metrics is obtained
// before the deletion is processing
// So the Pending Block count will be 3
Expand All @@ -633,9 +635,11 @@ public void testBlockDeletion(ContainerTestVersionInfo versionInfo)
assertEquals(3,
deletingServiceMetrics.getTotalBlockChosenCount()
- totalBlockChosenCount);
assertEquals(1, deletingServiceMetrics.getBlockChosenCountInLastIteration());
assertEquals(2,
deletingServiceMetrics.getTotalContainerChosenCount()
- totalContainerChosenCount);
assertEquals(1, deletingServiceMetrics.getContainerChosenCountInLastIteration());

// check if blockData get deleted
assertBlockDataTableRecordCount(0, meta, filter, data.getContainerID());
Expand Down

0 comments on commit 4573baf

Please sign in to comment.