Skip to content

Commit 8b11391

Browse files
author
chengyitian
committed
AJ-762: optimize log info for MultithreadedTableWriter;
1 parent 45cf108 commit 8b11391

File tree

1 file changed

+28
-11
lines changed

1 file changed

+28
-11
lines changed

src/com/xxdb/multithreadedtablewriter/MultithreadedTableWriter.java

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,16 @@
55
import com.xxdb.data.*;
66
import com.xxdb.route.Domain;
77
import com.xxdb.route.DomainFactory;
8+
import org.slf4j.LoggerFactory;
89
import java.io.IOException;
910
import java.time.LocalDateTime;
1011
import java.util.ArrayList;
1112
import java.util.List;
1213
import java.util.Objects;
13-
import java.util.logging.Logger;
14-
1514
import static com.xxdb.data.Entity.DATA_TYPE.*;
1615

1716
public class MultithreadedTableWriter {
18-
private Logger logger_=Logger.getLogger(getClass().getName());
17+
private static final org.slf4j.Logger log = LoggerFactory.getLogger(MultithreadedTableWriter.class);
1918
public static class ThreadStatus{
2019
public long threadId;
2120
public long sentRows, unsentRows, sendFailedRows;
@@ -173,7 +172,7 @@ boolean writeAllData(){
173172
writeTable = new BasicTable(colNames, items);
174173
}catch (Exception e){
175174
e.printStackTrace();
176-
tableWriter_.logger_.warning("threadid=" + writeThread_.getId() + " sendindex=" + sentRows_ + " create table error: " + e);
175+
tableWriter_.log.warn("threadid=" + writeThread_.getId() + " sendindex=" + sentRows_ + " create table error: " + e);
177176
tableWriter_.setError(ErrorCodeInfo.Code.EC_Server, "Failed to createTable: " + e);
178177
isWriteDone = false;
179178
}
@@ -200,7 +199,7 @@ boolean writeAllData(){
200199
sentRows_ += addRowCount;
201200
} catch (Exception e) {
202201
e.printStackTrace();
203-
tableWriter_.logger_.warning("threadid=" + writeThread_.getId() + " sendindex=" + sentRows_ + " Save table error: " + e + " script:" + runscript);
202+
tableWriter_.log.warn("threadid=" + writeThread_.getId() + " sendindex=" + sentRows_ + " Save table error: " + e + " script:" + runscript);
204203
tableWriter_.setError(ErrorCodeInfo.Code.EC_Server, "Failed to save the inserted data: " + e + " script: " + runscript);
205204
isWriteDone = false;
206205
tableWriter_.hasError_ = true;
@@ -770,7 +769,7 @@ public ErrorCodeInfo insert(Object... args){
770769
(enableActualSendTime_ && args.length != colInfos_.length - 1)) {
771770
return new ErrorCodeInfo(ErrorCodeInfo.Code.EC_InvalidParameter, "Column counts don't match.");
772771
}
773-
try {
772+
774773
List<Entity> prow=new ArrayList<>();
775774
int colindex = 0;
776775
Entity.DATA_TYPE dataType;
@@ -779,25 +778,43 @@ public ErrorCodeInfo insert(Object... args){
779778
dataType = colInfos_[colindex].type_;
780779
Entity entity;
781780
isAllNull = false;
782-
entity = BasicEntityFactory.createScalar(dataType, one, colInfos_[colindex].extra_);
781+
try {
782+
entity = BasicEntityFactory.createScalar(dataType, one, colInfos_[colindex].extra_);
783+
} catch (Exception e) {
784+
String errorMsg = "Invalid object error when create scalar for column '" + colInfos_[colindex].name_ + "': " + e.getMessage();
785+
log.error(errorMsg);
786+
return new ErrorCodeInfo(ErrorCodeInfo.Code.EC_InvalidObject, errorMsg);
787+
}
788+
783789
if (entity == null) {
784790
return new ErrorCodeInfo(ErrorCodeInfo.Code.EC_InvalidObject, "Data conversion error: " + dataType);
785791
}
792+
786793
prow.add(entity);
787794
colindex++;
788795
}
796+
789797
if (enableActualSendTime_) {
790798
dataType = colInfos_[colindex].type_;
791799
if (dataType != DT_NANOTIMESTAMP)
792800
return new ErrorCodeInfo(ErrorCodeInfo.Code.EC_InvalidObject, String.format("Data type error: %s,should be NANOTIMESTAMP.", dataType));
793801
Entity entity;
794802
isAllNull = false;
795-
entity = BasicEntityFactory.createScalar(dataType, null, colInfos_[colindex].extra_);
803+
try {
804+
entity = BasicEntityFactory.createScalar(dataType, null, colInfos_[colindex].extra_);
805+
} catch (Exception e) {
806+
String errorMsg = "Invalid object error when create scalar for column '" + colInfos_[colindex].name_ + "': " + e.getMessage();
807+
log.error(errorMsg);
808+
return new ErrorCodeInfo(ErrorCodeInfo.Code.EC_InvalidObject, errorMsg);
809+
}
810+
796811
prow.add(entity);
797812
}
798-
if(isAllNull){
813+
814+
try {
815+
if(isAllNull)
799816
return new ErrorCodeInfo(ErrorCodeInfo.Code.EC_InvalidObject, "Can't insert a Null row.");
800-
}
817+
801818
int threadindex;
802819
if(threads_.size() > 1){
803820
if(isPartionedTable_){
@@ -820,7 +837,7 @@ public ErrorCodeInfo insert(Object... args){
820837
insertThreadWrite(threadindex, prow);
821838
return new ErrorCodeInfo();
822839
}catch (Exception e){
823-
e.printStackTrace();
840+
log.error(e.getMessage());
824841
return new ErrorCodeInfo(ErrorCodeInfo.Code.EC_InvalidObject, "Invalid object error " + e);
825842
}
826843
}

0 commit comments

Comments
 (0)