chore(project): 添加项目配置文件和忽略规则
- 添加 Babel 配置文件支持 ES6+ 语法转换 - 添加 ESLint 忽略规则和配置文件 - 添加 Git 忽略规则文件 - 添加 Travis CI 配置文件 - 添加 1.4.2 版本变更日志文件 - 添加 Helm 图表辅助模板文件 - 添加 Helm 忽略规则文件
This commit is contained in:
49
saga/seata-saga-rm/pom.xml
Normal file
49
saga/seata-saga-rm/pom.xml
Normal file
@@ -0,0 +1,49 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
~ Copyright 1999-2019 Seata.io Group.
|
||||
~
|
||||
~ Licensed 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.
|
||||
-->
|
||||
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>seata-saga</artifactId>
|
||||
<groupId>io.seata</groupId>
|
||||
<version>${revision}</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<name>seata-saga-rm ${project.version}</name>
|
||||
<artifactId>seata-saga-rm</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>seata-core</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>seata-rm</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>seata-saga-engine</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copyright 1999-2019 Seata.io Group.
|
||||
*
|
||||
* Licensed 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 io.seata.saga.rm;
|
||||
|
||||
import io.seata.core.model.BranchType;
|
||||
import io.seata.core.model.ResourceManager;
|
||||
import io.seata.core.protocol.transaction.UndoLogDeleteRequest;
|
||||
import io.seata.rm.AbstractRMHandler;
|
||||
import io.seata.rm.DefaultResourceManager;
|
||||
|
||||
/**
|
||||
* The type Rm handler SAGA.
|
||||
*
|
||||
* @author lorne.cl
|
||||
*/
|
||||
public class RMHandlerSaga extends AbstractRMHandler {
|
||||
|
||||
@Override
|
||||
public void handle(UndoLogDeleteRequest request) {
|
||||
//DO nothing
|
||||
}
|
||||
|
||||
/**
|
||||
* get SAGA resource manager
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
protected ResourceManager getResourceManager() {
|
||||
return DefaultResourceManager.get().getResourceManager(BranchType.SAGA);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BranchType getBranchType() {
|
||||
return BranchType.SAGA;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
/*
|
||||
* Copyright 1999-2019 Seata.io Group.
|
||||
*
|
||||
* Licensed 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 io.seata.saga.rm;
|
||||
|
||||
import io.seata.core.model.BranchType;
|
||||
import io.seata.core.model.Resource;
|
||||
|
||||
/**
|
||||
* Saga resource (Only register application as a saga resource)
|
||||
*
|
||||
* @author lorne.cl
|
||||
*/
|
||||
public class SagaResource implements Resource {
|
||||
|
||||
private String resourceGroupId;
|
||||
|
||||
private String applicationId;
|
||||
|
||||
/**
|
||||
* Gets get resource group id.
|
||||
*
|
||||
* @return the get resource group id
|
||||
*/
|
||||
@Override
|
||||
public String getResourceGroupId() {
|
||||
return resourceGroupId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets set resource group id.
|
||||
*
|
||||
* @param resourceGroupId the resource group id
|
||||
*/
|
||||
public void setResourceGroupId(String resourceGroupId) {
|
||||
this.resourceGroupId = resourceGroupId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets get resource id.
|
||||
*
|
||||
* @return the get resource id
|
||||
*/
|
||||
@Override
|
||||
public String getResourceId() {
|
||||
return applicationId + "#" + resourceGroupId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets get branch type.
|
||||
*
|
||||
* @return the get branch type
|
||||
*/
|
||||
@Override
|
||||
public BranchType getBranchType() {
|
||||
return BranchType.SAGA;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets get application id.
|
||||
*
|
||||
* @return the get application id
|
||||
*/
|
||||
public String getApplicationId() {
|
||||
return applicationId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets set application id.
|
||||
*
|
||||
* @param applicationId the application id
|
||||
*/
|
||||
public void setApplicationId(String applicationId) {
|
||||
this.applicationId = applicationId;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,164 @@
|
||||
/*
|
||||
* Copyright 1999-2019 Seata.io Group.
|
||||
*
|
||||
* Licensed 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 io.seata.saga.rm;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import io.seata.common.exception.FrameworkErrorCode;
|
||||
import io.seata.core.exception.TransactionException;
|
||||
import io.seata.core.model.BranchStatus;
|
||||
import io.seata.core.model.BranchType;
|
||||
import io.seata.core.model.GlobalStatus;
|
||||
import io.seata.core.model.Resource;
|
||||
import io.seata.rm.AbstractResourceManager;
|
||||
import io.seata.saga.engine.exception.EngineExecutionException;
|
||||
import io.seata.saga.engine.exception.ForwardInvalidException;
|
||||
import io.seata.saga.statelang.domain.ExecutionStatus;
|
||||
import io.seata.saga.statelang.domain.RecoverStrategy;
|
||||
import io.seata.saga.statelang.domain.StateMachineInstance;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* Saga resource manager
|
||||
*
|
||||
* @author lorne.cl
|
||||
*/
|
||||
public class SagaResourceManager extends AbstractResourceManager {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(SagaResourceManager.class);
|
||||
|
||||
/**
|
||||
* Saga resource cache
|
||||
*/
|
||||
private Map<String, Resource> sagaResourceCache = new ConcurrentHashMap<>();
|
||||
|
||||
/**
|
||||
* Instantiates a new saga resource manager.
|
||||
*/
|
||||
public SagaResourceManager() {
|
||||
}
|
||||
|
||||
/**
|
||||
* registry saga resource
|
||||
*
|
||||
* @param resource The resource to be managed.
|
||||
*/
|
||||
@Override
|
||||
public void registerResource(Resource resource) {
|
||||
SagaResource sagaResource = (SagaResource)resource;
|
||||
sagaResourceCache.put(sagaResource.getResourceId(), sagaResource);
|
||||
super.registerResource(sagaResource);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Resource> getManagedResources() {
|
||||
return sagaResourceCache;
|
||||
}
|
||||
|
||||
/**
|
||||
* SAGA branch commit
|
||||
*
|
||||
* @param branchType
|
||||
* @param xid Transaction id.
|
||||
* @param branchId Branch id.
|
||||
* @param resourceId Resource id.
|
||||
* @param applicationData Application data bind with this branch.
|
||||
* @return
|
||||
* @throws TransactionException
|
||||
*/
|
||||
@Override
|
||||
public BranchStatus branchCommit(BranchType branchType, String xid, long branchId, String resourceId,
|
||||
String applicationData) throws TransactionException {
|
||||
try {
|
||||
StateMachineInstance machineInstance = StateMachineEngineHolder.getStateMachineEngine().forward(xid, null);
|
||||
|
||||
if (ExecutionStatus.SU.equals(machineInstance.getStatus())
|
||||
&& machineInstance.getCompensationStatus() == null) {
|
||||
return BranchStatus.PhaseTwo_Committed;
|
||||
} else if (ExecutionStatus.SU.equals(machineInstance.getCompensationStatus())) {
|
||||
return BranchStatus.PhaseTwo_Rollbacked;
|
||||
} else if (ExecutionStatus.FA.equals(machineInstance.getCompensationStatus()) || ExecutionStatus.UN.equals(
|
||||
machineInstance.getCompensationStatus())) {
|
||||
return BranchStatus.PhaseTwo_RollbackFailed_Retryable;
|
||||
} else if (ExecutionStatus.FA.equals(machineInstance.getStatus())
|
||||
&& machineInstance.getCompensationStatus() == null) {
|
||||
return BranchStatus.PhaseOne_Failed;
|
||||
}
|
||||
|
||||
} catch (ForwardInvalidException e) {
|
||||
LOGGER.error("StateMachine forward failed, xid: " + xid, e);
|
||||
|
||||
//if StateMachineInstanceNotExists stop retry
|
||||
if (FrameworkErrorCode.StateMachineInstanceNotExists.equals(e.getErrcode())) {
|
||||
return BranchStatus.PhaseTwo_Committed;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LOGGER.error("StateMachine forward failed, xid: " + xid, e);
|
||||
}
|
||||
return BranchStatus.PhaseTwo_CommitFailed_Retryable;
|
||||
}
|
||||
|
||||
/**
|
||||
* SAGA branch rollback
|
||||
*
|
||||
* @param branchType the branch type
|
||||
* @param xid Transaction id.
|
||||
* @param branchId Branch id.
|
||||
* @param resourceId Resource id.
|
||||
* @param applicationData Application data bind with this branch.
|
||||
* @return
|
||||
* @throws TransactionException
|
||||
*/
|
||||
@Override
|
||||
public BranchStatus branchRollback(BranchType branchType, String xid, long branchId, String resourceId,
|
||||
String applicationData) throws TransactionException {
|
||||
try {
|
||||
StateMachineInstance stateMachineInstance = StateMachineEngineHolder.getStateMachineEngine().reloadStateMachineInstance(xid);
|
||||
if (stateMachineInstance == null) {
|
||||
return BranchStatus.PhaseTwo_Rollbacked;
|
||||
}
|
||||
if (RecoverStrategy.Forward.equals(stateMachineInstance.getStateMachine().getRecoverStrategy())
|
||||
&& (GlobalStatus.TimeoutRollbacking.name().equals(applicationData)
|
||||
|| GlobalStatus.TimeoutRollbackRetrying.name().equals(applicationData))) {
|
||||
LOGGER.warn("Retry by custom recover strategy [Forward] on timeout, SAGA global[{}]", xid);
|
||||
return BranchStatus.PhaseTwo_CommitFailed_Retryable;
|
||||
}
|
||||
|
||||
stateMachineInstance = StateMachineEngineHolder.getStateMachineEngine().compensate(xid,
|
||||
null);
|
||||
if (ExecutionStatus.SU.equals(stateMachineInstance.getCompensationStatus())) {
|
||||
return BranchStatus.PhaseTwo_Rollbacked;
|
||||
}
|
||||
} catch (EngineExecutionException e) {
|
||||
LOGGER.error("StateMachine compensate failed, xid: " + xid, e);
|
||||
|
||||
//if StateMachineInstanceNotExists stop retry
|
||||
if (FrameworkErrorCode.StateMachineInstanceNotExists.equals(e.getErrcode())) {
|
||||
return BranchStatus.PhaseTwo_Rollbacked;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LOGGER.error("StateMachine compensate failed, xid: " + xid, e);
|
||||
}
|
||||
return BranchStatus.PhaseTwo_RollbackFailed_Retryable;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BranchType getBranchType() {
|
||||
return BranchType.SAGA;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright 1999-2019 Seata.io Group.
|
||||
*
|
||||
* Licensed 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 io.seata.saga.rm;
|
||||
|
||||
import io.seata.saga.engine.StateMachineEngine;
|
||||
|
||||
/**
|
||||
* @author lorne.cl
|
||||
*/
|
||||
public class StateMachineEngineHolder {
|
||||
|
||||
private static StateMachineEngine stateMachineEngine;
|
||||
|
||||
public static StateMachineEngine getStateMachineEngine() {
|
||||
return stateMachineEngine;
|
||||
}
|
||||
|
||||
public void setStateMachineEngine(StateMachineEngine smEngine) {
|
||||
stateMachineEngine = smEngine;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
#
|
||||
# Copyright 1999-2019 Seata.io Group.
|
||||
#
|
||||
# Licensed 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.
|
||||
#
|
||||
|
||||
io.seata.saga.rm.SagaResourceManager
|
||||
@@ -0,0 +1,17 @@
|
||||
#
|
||||
# Copyright 1999-2019 Seata.io Group.
|
||||
#
|
||||
# Licensed 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.
|
||||
#
|
||||
|
||||
io.seata.saga.rm.RMHandlerSaga
|
||||
Reference in New Issue
Block a user