Skip to content

Commit

Permalink
优化nodb模块
Browse files Browse the repository at this point in the history
  • Loading branch information
xlorne committed Jan 22, 2018
1 parent 605208a commit d8b62ae
Show file tree
Hide file tree
Showing 12 changed files with 102 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public TransactionServer createTransactionServer(TxTransactionInfo info) throws
if (info.getTxTransactionLocal() != null) {
return txDefaultTransactionServer;
} else {
if(transactionControl.hasTransaction()) {//有事务业务的操作
if(!transactionControl.isNoTransactionOperation()) { //有事务业务的操作
return txRunningTransactionServer;
}else {
return txRunningNoTransactionServer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,12 @@ public void run0() {
//记录补偿日志
txManagerService.sendCompensateMsg(groupId, time, info,executeConnectionError);
}
}else{
if(rs==1){
lastState = 1;
}else{
lastState = 0;
}
}

task.setState(lastState);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

import com.alibaba.fastjson.JSONObject;
import com.codingapi.tx.control.service.IActionService;
import com.codingapi.tx.datasource.ILCNTransactionControl;
import com.codingapi.tx.framework.task.TaskGroup;
import com.codingapi.tx.framework.task.TaskGroupManager;
import com.codingapi.tx.framework.task.TaskState;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
Expand All @@ -19,38 +21,47 @@ public class ActionTServiceImpl implements IActionService {

private Logger logger = LoggerFactory.getLogger(ActionTServiceImpl.class);

@Autowired
private ILCNTransactionControl transactionControl;

@Override
public String execute(JSONObject resObj, String json) {
String res;
//通知提醒
final int state = resObj.getInteger("c");
String taskId = resObj.getString("t");
TaskGroup task = TaskGroupManager.getInstance().getTaskGroup(taskId);
logger.info("accept notify data ->" + json);
if (task != null) {
if (task.isAwait()) { //已经等待
res = notifyWaitTask(task, state);
} else {
int index = 0;
while (true) {
if (index > 500) {
res = "0";
break;
}
if (task.isAwait()) { //已经等待
res = notifyWaitTask(task, state);
break;
}
index++;
try {
Thread.sleep(1);
} catch (InterruptedException e) {
e.printStackTrace();
if(transactionControl.executeTransactionOperation()) {
TaskGroup task = TaskGroupManager.getInstance().getTaskGroup(taskId);
logger.info("accept notify data ->" + json);
if (task != null) {
if (task.isAwait()) { //已经等待
res = notifyWaitTask(task, state);
} else {
int index = 0;
while (true) {
if (index > 500) {
res = "0";
break;
}
if (task.isAwait()) { //已经等待
res = notifyWaitTask(task, state);
break;
}
index++;
try {
Thread.sleep(1);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
} else {
res = "0";
}
} else {
res = "0";
}else{
//非事务操作
res = "1";
transactionControl.autoNoTransactionOperation();
}
logger.info("accept notify response res ->" + res);
return res;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ public abstract class AbstractResourceProxy<C,T extends ILCNResource> implements
protected volatile int nowCount = 0;


private volatile boolean hasTransaction = false;

private volatile boolean isNoTransaction = false;



Expand Down Expand Up @@ -68,6 +71,10 @@ public void close(ILCNResource connection) {


protected ILCNResource loadConnection(){

//说明有db操作.
hasTransaction = true;

TxTransactionLocal txTransactionLocal = TxTransactionLocal.current();

if(txTransactionLocal==null){
Expand Down Expand Up @@ -150,11 +157,21 @@ public boolean hasGroup(String group){


@Override
public boolean hasTransaction() {
return true;
public boolean executeTransactionOperation() {
return hasTransaction;
}


@Override
public boolean isNoTransactionOperation() {
return isNoTransaction;
}

@Override
public void autoNoTransactionOperation() {
isNoTransaction = true;
}

public void setMaxWaitTime(int maxWaitTime) {
this.maxWaitTime = maxWaitTime;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,20 @@ public interface ILCNTransactionControl {
boolean hasGroup(String group);

/**
* 是否是 事务操作
* @return true是,false否
* 有无执行过事务操作
* @return true 有,false 否
*/
boolean hasTransaction();
boolean executeTransactionOperation();


/**
* 是否没有事务操作 default false
* @return true 是 false 否
*/
boolean isNoTransactionOperation();

/**
* 设置开启没有事务操作
*/
void autoNoTransactionOperation();
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ private void welcome(){
System.out.println("\t\t** \t\t** \t\t** ***");
System.out.println("\t\t*****\t\t ****\t\t** **");
System.out.println();
System.out.println("\t\tLCN version:4.0.3");
System.out.println("\t\tLCN-Client version:4.0.3");
System.out.println();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,8 @@ private boolean _executeCompensate(String json) throws ServiceException {

String res = managerSenderService.sendCompensateMsg(modelInfo.getChannelName(), groupId, data,startError);

logger.debug("executeCompensate->"+json+",@@->"+res);

return "1".equals(res);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,24 @@ public void start() {
Constants.socketPort = configReader.getSocketPort();
Constants.maxConnection = configReader.getSocketMaxConnection();
nettyServerService.start();

welcome();
}


private void welcome(){
System.out.println();
System.out.println();
System.out.println("\t\t** \t\t ****\t\t** **");
System.out.println("\t\t** \t\t** \t\t*** **");
System.out.println("\t\t** \t\t** \t\t** ***");
System.out.println("\t\t*****\t\t ****\t\t** **");
System.out.println();
System.out.println("\t\tLCN-TxManager version:4.0.3");
System.out.println();
}


@Override
public void close() {
nettyServerService.close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public TxState getState() {
state.setNotifyUrl(configReader.getCompensateNotifyUrl());
state.setCompensate(configReader.isCompensateAuto());
state.setCompensateTryTime(configReader.getCompensateTryTime());
state.setAutoCompensateLimit(configReader.getCompensateMaxWaitTime());
state.setCompensateMaxWaitTime(configReader.getCompensateMaxWaitTime());
state.setSlbList(getServices());
return state;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public static TxServer format(TxState state) {
txServer.setPort(state.getPort());
txServer.setHeart(state.getTransactionNettyHeartTime());
txServer.setDelay(state.getTransactionNettyDelayTime());
txServer.setCompensateMaxWaitTime(state.getAutoCompensateLimit());
txServer.setCompensateMaxWaitTime(state.getCompensateMaxWaitTime());
return txServer;
}

Expand Down
10 changes: 5 additions & 5 deletions tx-manager/src/main/java/com/codingapi/tm/model/TxState.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public class TxState {
/**
* 自动补偿间隔时间
*/
private int autoCompensateLimit;
private int compensateMaxWaitTime;


public String getIp() {
Expand Down Expand Up @@ -158,12 +158,12 @@ public void setNotifyUrl(String notifyUrl) {
this.notifyUrl = notifyUrl;
}

public int getAutoCompensateLimit() {
return autoCompensateLimit;
public int getCompensateMaxWaitTime() {
return compensateMaxWaitTime;
}

public void setAutoCompensateLimit(int autoCompensateLimit) {
this.autoCompensateLimit = autoCompensateLimit;
public void setCompensateMaxWaitTime(int compensateMaxWaitTime) {
this.compensateMaxWaitTime = compensateMaxWaitTime;
}


Expand Down
1 change: 1 addition & 0 deletions tx-manager/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,4 @@ tm.compensate.maxWaitTime=5000



logging.level.com.codingapi=debug

0 comments on commit d8b62ae

Please sign in to comment.