Skip to content

Commit

Permalink
optimize: datasource manager branch rollback exception log (apache#1775)
Browse files Browse the repository at this point in the history
  • Loading branch information
jsbxyyx authored and zjinlei committed Dec 18, 2019
1 parent 4196b31 commit 8bd59bf
Show file tree
Hide file tree
Showing 8 changed files with 104 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,11 @@ public class ConfigurationKeys {
*/
public static final String TRANSACTION_UNDO_LOG_TABLE = CLIENT_UNDO_PREFIX + "log.table";

/**
* The constant TRANSACTION_UNDO_LOG_EXCEPTION_RATE
*/
public static final String TRANSACTION_LOG_EXCEPTION_RATE = CLIENT_PREFIX + "log.exceptionRate";

/**
* The constant TRANSACTION_UNDO_LOG_DEFAULT_TABLE.
*/
Expand Down
41 changes: 41 additions & 0 deletions core/src/main/java/io/seata/core/logger/StackTraceLogger.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* 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.core.logger;

import io.seata.config.Configuration;
import io.seata.config.ConfigurationFactory;
import io.seata.core.constants.ConfigurationKeys;
import org.slf4j.Logger;

/**
* @author jsbxyyx
*/
public final class StackTraceLogger {

private static final Configuration CONFIG = ConfigurationFactory.getInstance();

public static void info(Logger logger, Throwable cause, String format1, Object[] args1, String format2, Object[] args2) {
if (logger.isInfoEnabled()) {
int rate = CONFIG.getInt(ConfigurationKeys.TRANSACTION_LOG_EXCEPTION_RATE, 100);
if (System.currentTimeMillis() % rate == 0) {
logger.info(format1, args1, cause);
} else {
logger.info(format2, args2);
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import io.seata.core.exception.RmTransactionException;
import io.seata.core.exception.TransactionException;
import io.seata.core.exception.TransactionExceptionCode;
import io.seata.core.logger.StackTraceLogger;
import io.seata.core.model.BranchStatus;
import io.seata.core.model.BranchType;
import io.seata.core.model.Resource;
Expand Down Expand Up @@ -179,9 +180,10 @@ public BranchStatus branchRollback(BranchType branchType, String xid, long branc
try {
UndoLogManagerFactory.getUndoLogManager(dataSourceProxy.getDbType()).undo(dataSourceProxy, xid, branchId);
} catch (TransactionException te) {
if (LOGGER.isInfoEnabled()) {
LOGGER.info("branchRollback failed reason [{}]", te.getMessage());
}
StackTraceLogger.info(LOGGER, te,
"[stacktrace]branchRollback failed. branchType:[{}], xid:[{}], branchId:[{}], resourceId:[{}], applicationData:[{}]. stacktrace:[{}]",
new Object[]{branchType, xid, branchId, resourceId, applicationData, te.getMessage()},
"branchRollback failed reason [{}]", new Object[]{te.getMessage()});
if (te.getCode() == TransactionExceptionCode.BranchRollbackFailed_Unretriable) {
return BranchStatus.PhaseTwo_RollbackFailed_Unretryable;
} else {
Expand Down
3 changes: 3 additions & 0 deletions script/client/conf/file.conf
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ client {
log.serialization = "jackson"
log.table = "undo_log"
}
log {
exceptionRate = 100
}
support {
# auto proxy the DataSource bean
spring.datasource.autoproxy = false
Expand Down
1 change: 1 addition & 0 deletions script/config-center/nacos/nacos-config.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ client.undo.log.serialization=jackson
server.undo.log.save.days=7
server.undo.log.delete.period=86400000
client.undo.log.table=undo_log
client.log.exceptionRate=100
transport.serialization=seata
transport.compressor=none
metrics.enabled=false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,16 @@
*/
package io.seata.spring.boot.autoconfigure;

import java.util.HashMap;

import io.seata.spring.boot.autoconfigure.properties.file.ClientProperties;
import io.seata.spring.boot.autoconfigure.properties.file.LockProperties;
import io.seata.spring.boot.autoconfigure.properties.file.LogProperties;
import io.seata.spring.boot.autoconfigure.properties.file.ServiceProperties;
import io.seata.spring.boot.autoconfigure.properties.file.ShutdownProperties;
import io.seata.spring.boot.autoconfigure.properties.file.SpringProperties;
import io.seata.spring.boot.autoconfigure.properties.file.SupportProperties;
import io.seata.spring.boot.autoconfigure.properties.file.ThreadFactoryProperties;
import io.seata.spring.boot.autoconfigure.properties.file.UndoProperties;
import io.seata.spring.boot.autoconfigure.properties.file.TransportProperties;
import io.seata.spring.boot.autoconfigure.properties.file.UndoProperties;
import io.seata.spring.boot.autoconfigure.properties.registry.ConfigApolloProperties;
import io.seata.spring.boot.autoconfigure.properties.registry.ConfigConsulProperties;
import io.seata.spring.boot.autoconfigure.properties.registry.ConfigEtcd3Properties;
Expand All @@ -43,6 +42,8 @@
import io.seata.spring.boot.autoconfigure.properties.registry.RegistrySofaProperties;
import io.seata.spring.boot.autoconfigure.properties.registry.RegistryZooKeeperProperties;

import java.util.HashMap;

/**
* @author xingfudeshi@gmail.com
* @date 2019/09/30
Expand All @@ -59,6 +60,7 @@ public class StarterConstants {
public static final String CLIENT_RM_PREFIX = CLIENT_PREFIX + ".rm";
public static final String LOCK_PREFIX = CLIENT_RM_PREFIX + ".lock";
public static final String UNDO_PREFIX = CLIENT_PREFIX + ".undo";
public static final String LOG_PREFIX = CLIENT_PREFIX + ".log";
public static final String SUPPORT_PREFIX = CLIENT_PREFIX + ".support";
public static final String SPRING_PREFIX = SUPPORT_PREFIX + ".spring";

Expand Down Expand Up @@ -92,6 +94,7 @@ public class StarterConstants {
put(SUPPORT_PREFIX, SupportProperties.class);
put(THREAD_FACTORY_PREFIX, ThreadFactoryProperties.class);
put(UNDO_PREFIX, UndoProperties.class);
put(LOG_PREFIX, LogProperties.class);
put(TRANSPORT_PREFIX, TransportProperties.class);
put(CONFIG_PREFIX, ConfigProperties.class);
put(CONFIG_FILE_PREFIX, ConfigFileProperties.class);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* 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.spring.boot.autoconfigure.properties.file;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import static io.seata.spring.boot.autoconfigure.StarterConstants.LOG_PREFIX;

/**
* @author jsbxyyx
*/
@Component
@ConfigurationProperties(prefix = LOG_PREFIX)
public class LogProperties {

private int exceptionRate = 100;

public int getExceptionRate() {
return exceptionRate;
}

public LogProperties setExceptionRate(int exceptionRate) {
this.exceptionRate = exceptionRate;
return this;
}
}
3 changes: 3 additions & 0 deletions server/src/main/resources/file.conf.example
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ client {
log.serialization = "jackson"
log.table = "undo_log"
}
log {
exceptionRate = 100
}
support {
# auto proxy the DataSource bean
spring.datasource.autoproxy = false
Expand Down

0 comments on commit 8bd59bf

Please sign in to comment.