-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #567 from ballerina-platform/transaction-recovery
Logging for Transaction Recovery in a 2PC Transaction
- Loading branch information
Showing
12 changed files
with
124 additions
and
20 deletions.
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
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
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
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
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
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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
[ballerina.lang.transaction] | ||
recoveryLogDir="./target/transactionLogs" | ||
recoveryLogName="testLogs" | ||
checkpointInterval=-1 |
47 changes: 47 additions & 0 deletions
47
...action-native/src/main/java/org/ballerinalang/stdlib/transaction/TransactionRecovery.java
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 |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// Copyright (c) 2024 WSO2 Inc. (http://www.wso2.org) | ||
// | ||
// WSO2 Inc. licenses this file to you under the Apache License, | ||
// Version 2.0 (the "License"); you may not use this file except | ||
// in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
package org.ballerinalang.stdlib.transaction; | ||
|
||
import io.ballerina.runtime.api.values.BString; | ||
import io.ballerina.runtime.transactions.RecoveryState; | ||
import io.ballerina.runtime.transactions.TransactionLogRecord; | ||
import io.ballerina.runtime.transactions.TransactionResourceManager; | ||
|
||
public class TransactionRecovery { | ||
|
||
public static void writeToLog(BString trxId, BString transactionBlockId, BString transactionStatus) { | ||
if (TransactionResourceManager.getInstance().getTransactionManagerEnabled()) { | ||
return; | ||
} | ||
TransactionLogRecord logRecord = createLogRecord(trxId, transactionBlockId, transactionStatus); | ||
TransactionResourceManager.getInstance().getLogManager().put(logRecord); | ||
} | ||
|
||
private static TransactionLogRecord createLogRecord(BString trxId, BString transactionBlockId, | ||
BString transactionStatus) { | ||
return new TransactionLogRecord(trxId.getValue(), transactionBlockId.getValue(), | ||
RecoveryState.valueOf(transactionStatus.getValue())); | ||
} | ||
|
||
public static void startupCrashRecovery() { | ||
if (TransactionResourceManager.getInstance().getTransactionManagerEnabled()) { | ||
// if atomikos tm is used, we skip startup crash recovery. | ||
return; | ||
} | ||
TransactionResourceManager.getInstance().startupCrashRecovery(); | ||
} | ||
} |