-
Notifications
You must be signed in to change notification settings - Fork 511
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
HDDS-11714. resetDeletedBlockRetryCount with --all may fail and can cause long db lock in large cluster #7665
Open
aryangupta1998
wants to merge
4
commits into
apache:master
Choose a base branch
from
aryangupta1998:HDDS-11714
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+66
−39
Open
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,7 +19,6 @@ | |
|
||
import java.io.IOException; | ||
import java.time.Duration; | ||
import java.util.HashSet; | ||
import java.util.List; | ||
import java.util.UUID; | ||
import java.util.Set; | ||
|
@@ -31,6 +30,7 @@ | |
import java.util.stream.Collectors; | ||
|
||
import com.google.common.annotations.VisibleForTesting; | ||
import com.google.common.collect.Lists; | ||
import org.apache.hadoop.hdds.conf.ConfigurationSource; | ||
import org.apache.hadoop.hdds.protocol.DatanodeDetails; | ||
import org.apache.hadoop.hdds.protocol.proto.StorageContainerDatanodeProtocolProtos.CommandStatus; | ||
|
@@ -53,7 +53,6 @@ | |
import org.apache.hadoop.hdds.utils.db.Table; | ||
import org.apache.hadoop.hdds.utils.db.TableIterator; | ||
|
||
import com.google.common.collect.Lists; | ||
import static org.apache.hadoop.hdds.scm.ScmConfigKeys.OZONE_SCM_BLOCK_DELETION_MAX_RETRY; | ||
import static org.apache.hadoop.hdds.scm.ScmConfigKeys.OZONE_SCM_BLOCK_DELETION_MAX_RETRY_DEFAULT; | ||
import static org.apache.hadoop.hdds.scm.block.SCMDeletedBlockTransactionStatusManager.SCMDeleteBlocksCommandStatusManager.CmdStatus; | ||
|
@@ -121,6 +120,33 @@ public DeletedBlockLogImpl(ConfigurationSource conf, | |
containerManager, this.scmContext, metrics, scmCommandTimeoutMs); | ||
} | ||
|
||
@Override | ||
public List<DeletedBlocksTransaction> getFailedTransactionsBatch( | ||
int batchSize, long startTxId) throws IOException { | ||
List<DeletedBlocksTransaction> failedTXs = new ArrayList<>(); | ||
|
||
lock.lock(); | ||
try { | ||
try ( | ||
TableIterator<Long, ? extends Table.KeyValue<Long, DeletedBlocksTransaction>> iter = | ||
deletedBlockLogStateManager.getReadOnlyIterator()) { | ||
|
||
iter.seek(startTxId); | ||
|
||
while (iter.hasNext() && failedTXs.size() < batchSize) { | ||
DeletedBlocksTransaction delTX = iter.next().getValue(); | ||
if (delTX.getCount() == -1) { | ||
failedTXs.add(delTX); | ||
} | ||
} | ||
} | ||
} finally { | ||
lock.unlock(); | ||
} | ||
|
||
return failedTXs; | ||
} | ||
|
||
@Override | ||
public List<DeletedBlocksTransaction> getFailedTransactions(int count, | ||
long startTxId) throws IOException { | ||
|
@@ -129,7 +155,7 @@ public List<DeletedBlocksTransaction> getFailedTransactions(int count, | |
final List<DeletedBlocksTransaction> failedTXs = Lists.newArrayList(); | ||
try (TableIterator<Long, | ||
? extends Table.KeyValue<Long, DeletedBlocksTransaction>> iter = | ||
deletedBlockLogStateManager.getReadOnlyIterator()) { | ||
deletedBlockLogStateManager.getReadOnlyIterator()) { | ||
if (count == LIST_ALL_FAILED_TRANSACTIONS) { | ||
while (iter.hasNext()) { | ||
DeletedBlocksTransaction delTX = iter.next().getValue(); | ||
|
@@ -176,19 +202,72 @@ public void incrementCount(List<Long> txIDs) | |
*/ | ||
@Override | ||
public int resetCount(List<Long> txIDs) throws IOException { | ||
lock.lock(); | ||
final int batchSize = 100; | ||
int totalProcessed = 0; | ||
long startTxId = 0; | ||
|
||
try { | ||
// If txIDs are not provided, fetch all failed transactions in batches | ||
if (txIDs == null || txIDs.isEmpty()) { | ||
txIDs = getFailedTransactions(LIST_ALL_FAILED_TRANSACTIONS, 0).stream() | ||
.map(DeletedBlocksTransaction::getTxID) | ||
.collect(Collectors.toList()); | ||
List<DeletedBlocksTransaction> batch; | ||
do { | ||
// Fetch the batch of failed transactions | ||
batch = getFailedTransactionsBatch(batchSize, startTxId); | ||
|
||
// If the batch is empty, skip further processing | ||
if (!batch.isEmpty()) { | ||
List<Long> batchTxIDs = batch.stream() | ||
.map(DeletedBlocksTransaction::getTxID) | ||
.collect(Collectors.toList()); | ||
|
||
lock.lock(); | ||
try { | ||
transactionStatusManager.resetRetryCount(batchTxIDs); | ||
int batchProcessed = deletedBlockLogStateManager.resetRetryCountOfTransactionInDB( | ||
new ArrayList<>(batchTxIDs)); | ||
|
||
totalProcessed += batchProcessed; | ||
} finally { | ||
lock.unlock(); | ||
} | ||
|
||
// Update startTxId to continue from the last processed transaction in the next iteration | ||
startTxId = batch.get(batch.size() - 1).getTxID() + 1; | ||
} | ||
|
||
} while (!batch.isEmpty()); | ||
} else { | ||
// Process txIDs provided by the user in batches | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The user provided list of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
for (List<Long> batch : partitionList(txIDs, batchSize)) { | ||
lock.lock(); | ||
try { | ||
transactionStatusManager.resetRetryCount(batch); | ||
int batchProcessed = deletedBlockLogStateManager.resetRetryCountOfTransactionInDB( | ||
new ArrayList<>(batch)); | ||
|
||
totalProcessed += batchProcessed; | ||
} finally { | ||
lock.unlock(); | ||
} | ||
} | ||
} | ||
transactionStatusManager.resetRetryCount(txIDs); | ||
return deletedBlockLogStateManager.resetRetryCountOfTransactionInDB( | ||
new ArrayList<>(new HashSet<>(txIDs))); | ||
} finally { | ||
lock.unlock(); | ||
|
||
return totalProcessed; | ||
} catch (Exception e) { | ||
throw new IOException("Error during transaction reset", e); | ||
} | ||
} | ||
|
||
|
||
/** | ||
* Helper method to partition a list into smaller batches. | ||
*/ | ||
private <T> List<List<T>> partitionList(List<T> list, int batchSize) { | ||
List<List<T>> partitions = new ArrayList<>(); | ||
for (int i = 0; i < list.size(); i += batchSize) { | ||
partitions.add(list.subList(i, Math.min(i + batchSize, list.size()))); | ||
} | ||
return partitions; | ||
} | ||
|
||
private DeletedBlocksTransaction constructNewTransaction( | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need this additional method? The same thing can be achieved with the existing
getFailedTransactions
method.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done