Skip to content

Commit

Permalink
Merge pull request #41506 from dsplayerX/fix_41281_master
Browse files Browse the repository at this point in the history
[master] Fix TypeCastError in concurrent transactions
  • Loading branch information
gimantha authored Jan 3, 2024
2 parents a09cc05 + 20d0438 commit bceb4d9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,14 @@ private TransactionLocalContext(String globalTransactionId, String url, String p
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);
}

private void validateAndPutTransactionInfo(ByteBuffer transactionIdBytes, Object infoRecord) {
if (infoRecord == null) {
return;
}
transactionResourceManager.transactionInfoMap.put(transactionIdBytes, infoRecord);
}

public static TransactionLocalContext createTransactionParticipantLocalCtx(String globalTransactionId,
Expand Down Expand Up @@ -228,7 +234,7 @@ public void setResourceParticipant(boolean resourceParticipant) {
}

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

public boolean isTransactional() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ private TransactionResourceManager() {
resourceRegistry = new HashMap<>();
committedFuncRegistry = new HashMap<>();
abortedFuncRegistry = new HashMap<>();
transactionInfoMap = new HashMap<>();
transactionInfoMap = new ConcurrentHashMap<>();
transactionManagerEnabled = getTransactionManagerEnabled();
if (transactionManagerEnabled) {
trxRegistry = new HashMap<>();
Expand Down Expand Up @@ -610,6 +610,11 @@ public void notifyLocalParticipantFailure(String gTransactionId, String blockId)
}

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

0 comments on commit bceb4d9

Please sign in to comment.