Skip to content
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

[2201.7.x] Fix TypeCastError in concurrent transactions #41505

Merged
merged 2 commits into from
Jan 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,14 @@
this.rollbackOnlyError = null;
this.isTransactional = true;
this.transactionId = ValueCreator.createArrayValue(globalTransactionId.getBytes());
transactionResourceManager.transactionInfoMap.put(ByteBuffer.wrap(transactionId.getBytes().clone()),
infoRecord);
validateAndPutTransactionInfo(ByteBuffer.wrap(transactionId.getBytes().clone()), infoRecord);
}

Check warning on line 68 in bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/transactions/TransactionLocalContext.java

View check run for this annotation

Codecov / codecov/patch

bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/transactions/TransactionLocalContext.java#L67-L68

Added lines #L67 - L68 were not covered by tests

private void validateAndPutTransactionInfo(ByteBuffer transactionIdBytes, Object infoRecord) {
if (infoRecord == null) {
return;

Check warning on line 72 in bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/transactions/TransactionLocalContext.java

View check run for this annotation

Codecov / codecov/patch

bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/transactions/TransactionLocalContext.java#L72

Added line #L72 was not covered by tests
}
transactionResourceManager.transactionInfoMap.put(transactionIdBytes, infoRecord);

Check warning on line 74 in bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/transactions/TransactionLocalContext.java

View check run for this annotation

Codecov / codecov/patch

bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/transactions/TransactionLocalContext.java#L74

Added line #L74 was not covered by tests
}

public static TransactionLocalContext createTransactionParticipantLocalCtx(String globalTransactionId,
Expand Down Expand Up @@ -228,7 +234,7 @@
}

public Object getInfoRecord() {
return transactionResourceManager.transactionInfoMap.get(ByteBuffer.wrap(transactionId.getBytes()));
return transactionResourceManager.getTransactionRecord(transactionId);

Check warning on line 237 in bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/transactions/TransactionLocalContext.java

View check run for this annotation

Codecov / codecov/patch

bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/transactions/TransactionLocalContext.java#L237

Added line #L237 was not covered by tests
}

public boolean isTransactional() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@
resourceRegistry = new HashMap<>();
committedFuncRegistry = new HashMap<>();
abortedFuncRegistry = new HashMap<>();
transactionInfoMap = new HashMap<>();
transactionInfoMap = new ConcurrentHashMap<>();

Check warning on line 109 in bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/transactions/TransactionResourceManager.java

View check run for this annotation

Codecov / codecov/patch

bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/transactions/TransactionResourceManager.java#L109

Added line #L109 was not covered by tests
transactionManagerEnabled = getTransactionManagerEnabled();
if (transactionManagerEnabled) {
trxRegistry = new HashMap<>();
Expand Down Expand Up @@ -606,6 +606,11 @@
}

public Object getTransactionRecord(BArray xid) {
return transactionInfoMap.get(ByteBuffer.wrap(xid.getBytes()));
synchronized (transactionInfoMap) {

Check warning on line 609 in bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/transactions/TransactionResourceManager.java

View check run for this annotation

Codecov / codecov/patch

bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/transactions/TransactionResourceManager.java#L609

Added line #L609 was not covered by tests
if (transactionInfoMap.containsKey(ByteBuffer.wrap(xid.getBytes()))) {
return transactionInfoMap.get(ByteBuffer.wrap(xid.getBytes()));

Check warning on line 611 in bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/transactions/TransactionResourceManager.java

View check run for this annotation

Codecov / codecov/patch

bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/transactions/TransactionResourceManager.java#L611

Added line #L611 was not covered by tests
}
return null;

Check warning on line 613 in bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/transactions/TransactionResourceManager.java

View check run for this annotation

Codecov / codecov/patch

bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/transactions/TransactionResourceManager.java#L613

Added line #L613 was not covered by tests
}
}
}
Loading