提交 65e2f89a 编写于 作者: zc's avatar zc

fix:批量新增性能下降修改

上级 92d8d3ff
......@@ -159,39 +159,29 @@ public class ExecResultRepository {
PreparedStatement ps2 = this.getDeleteStatement2();
BatchStatement deleteBatch = new BatchStatement();
deleteBatch.setConsistencyLevel(ConsistencyLevel.ANY);// 设置一致性
BatchStatement deleteBatch2 = new BatchStatement();
deleteBatch2.setConsistencyLevel(ConsistencyLevel.ANY);// 设置一致性
for (ExecResult2 result2 : list) {
BoundStatement bs = ps.bind(result2.getRuleid(), 1, result2.getDimfield(), result2.getTimefield(), result2.getDomainsfield(), result2.getKeyvaluefield());
BoundStatement bs2 = ps2.bind(result2.getRuleid(), result2.getKeyvaluefield(), result2.getDimfield(), result2.getDomainsfield(), result2.getTimefield());
deleteBatch.add(bs);
deleteBatch.add(bs2);
deleteBatch2.add(bs2);
if ( deleteBatch.size() > batchSize) {
session.execute(deleteBatch);
deleteBatch.clear();
session.execute(deleteBatch2);
deleteBatch2.clear();
}
}
if (deleteBatch.size() > 0) {
session.execute(deleteBatch);
deleteBatch.clear();
session.execute(deleteBatch2);
deleteBatch2.clear();
}
//保存数据
BatchStatement batch = new BatchStatement();
batch.setConsistencyLevel(ConsistencyLevel.ANY);// 设置一致性
PreparedStatement savePs1 = this.getInsertStatement();
PreparedStatement savePs2 = this.getInsertStatement2();
for (ExecResult item : results) {
BoundStatement bs1 = savePs1.bind(item.getRuleid(), item.getRetvalue(), item.getDimfield(), item.getTimefield(), item.getDomainsfield(), item.getKeyvaluefield(),
item.getBusinesscat(), item.getExt1field(), item.getExt2field(), item.getMetricfield(), item.getRuexecresultname(), item.getRulename(), item.getUpdatedate());
BoundStatement bs2 = savePs2.bind(item.getRuleid(), item.getKeyvaluefield(), item.getDimfield(),item.getDomainsfield(), item.getTimefield());
batch.add(bs1);
batch.add(bs2);
if ( batch.size() > batchSize) {
session.execute(batch);
batch.clear();
}
}
if (batch.size() > 0) {
session.execute(batch);
batch.clear();
for (ExecResult execResult : results) {
save(execResult);
}
} catch (Exception e){
log.error("cassandra保存错误原因:" + e.getMessage());
......@@ -404,21 +394,6 @@ public class ExecResultRepository {
return deleteStatement2;
}
private PreparedStatement insertStatement = null;
public PreparedStatement getInsertStatement(){
if(insertStatement == null){
insertStatement = session.prepare("insert into ru_execresult(ruleid, retvalue, dimfield, timefield, domainsfield, keyvaluefield, " +
"businesscat, ext_1field, ext_2field, metricfield, ruexecresultname, rulename, updatedate) values(?,?,?,?,?,?,?,?,?,?,?,?,?)");
}
return insertStatement;
}
private PreparedStatement insertStatement2 = null;
public PreparedStatement getInsertStatement2(){
if(insertStatement2 == null){
insertStatement2 = session.prepare("insert into ru_execresult2(ruleid, keyvaluefield, dimfield, domainsfield, timefield) values(?,?,?,?,?)");
}
return insertStatement2;
}
/**
* 根据指标标识,业务数据主键,删除cql结果数据
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册