Skip to content

Commit

Permalink
处理下tddl rule并发问题
Browse files Browse the repository at this point in the history
  • Loading branch information
agapple committed Jan 23, 2014
1 parent 80bf5e7 commit 8bca529
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,15 @@ public void init() throws TddlException {
if (isInited()) {
return;
}
isInited = true;
doInit();

try {
doInit();
isInited = true;
} catch (Exception e) {
// 出现异常调用destory方法,释放
doDestory();
throw new TddlException(e);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,12 @@
import com.taobao.tddl.common.jdbc.ParameterContext;
import com.taobao.tddl.common.jdbc.ParameterMethod;
import com.taobao.tddl.common.model.SqlType;
import com.taobao.tddl.common.utils.logger.Logger;
import com.taobao.tddl.common.utils.logger.LoggerFactory;
import com.taobao.tddl.executor.common.ExecutionContext;
import com.taobao.tddl.matrix.jdbc.utils.PreParser;

import com.taobao.tddl.common.utils.logger.Logger;
import com.taobao.tddl.common.utils.logger.LoggerFactory;

/**
* @author mengshi.sunmengshi 2013-11-22 下午3:26:18
* @since 5.1.0
Expand Down Expand Up @@ -459,7 +460,7 @@ public void setNClob(int parameterIndex, Reader reader) throws SQLException {

@Override
public ParameterMetaData getParameterMetaData() throws SQLException {
throw new UnsupportedOperationException("getParameterMetaData");
throw new SQLException("getParameterMetaData");
}

}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.taobao.tddl.matrix.jdbc;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.SQLWarning;
Expand Down Expand Up @@ -52,8 +51,6 @@ public class TStatement implements Statement {
*/
protected boolean closed;

protected PreparedStatement proxyStatement;

private int maxFieldSize;

private int maxRows;
Expand Down Expand Up @@ -219,10 +216,6 @@ void close(boolean removeThis) throws SQLException {
return;
}
try {
if (this.proxyStatement != null) {
proxyStatement.close();
}

if (currentResultSet != null) {
currentResultSet.close();
}
Expand Down Expand Up @@ -337,10 +330,6 @@ public int getResultSetType() throws SQLException {
return resultSetType;
}

public void setProxyStatement(PreparedStatement ps) {
this.proxyStatement = ps;
}

public int getResultSetHoldability() throws SQLException {
return resultSetHoldability;
}
Expand Down
12 changes: 0 additions & 12 deletions tddl-rule/src/main/java/com/taobao/tddl/rule/VirtualTableRoot.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,18 +91,6 @@ private void initTableRule(String tableNameKey, TableRule tableRule) throws Tddl
logger.warn("virtual table inited :" + tableNameKey);
}

public Map<String, TableRule> getVirtualTableMap() {
return virtualTableMap;
}

public void setVirtualTableMap(Map<String, TableRule> virtualTableMap) {
this.virtualTableMap = virtualTableMap;
}

public Map<String, TableRule> getTableRules() {
return virtualTableMap;
}

public String getDefaultDbIndex() {
return defaultDbIndex;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,8 @@ private MatcherResult matchWithSourceKey(ComparativeMapChoicer choicer, List<Obj
if (dbRule == null && tbRule == null) {
// 若无库规则,静态拓扑里面只有一个库,则无论没表规则也好,全表扫也好,结果都和静态拓扑一样
// 若有库规则,那么是全库扫,则无论没表规则也好,全表扫也好,结果仍然和静态拓扑一样!!
topology = new HashMap<String, Map<String, Field>>(rule.getActualTopology().size());
Map<String, Set<String>> actualTopology = rule.getActualTopology();
topology = new HashMap<String, Map<String, Field>>(actualTopology.size());
for (Map.Entry<String, Set<String>> e : rule.getActualTopology().entrySet()) {
topology.put(e.getKey(), toMapField(e.getValue()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ public abstract class VirtualTableSupport extends AbstractLifecycle implements L
protected String[] tbRuleParames;

/** ============ 运行时变量 ================= **/
protected DBType dbType = DBType.MYSQL; // Oracle|MySql
protected String virtualTbName; // 逻辑表名
protected DBType dbType = DBType.MYSQL; // Oracle|MySql
protected String virtualTbName; // 逻辑表名
protected Map<String, Set<String>> actualTopology;

// ==================== 参数处理方法 ====================
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,6 @@ public static void tearDown() throws TddlException {
rule.destory();
}

@Test
public void testGetRules() {
List<String> versions = rule.getAllVersions();
for (String version : versions) {
VirtualTableRoot vtr = rule.getVersionRule(version);
for (VirtualTableRule table : vtr.getVirtualTableMap().values()) {
System.out.println(table.getActualTopology());
}
}
}

@Test
public void testTddlRuleMuRulesAndCompare_Select() {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Expand Down

0 comments on commit 8bca529

Please sign in to comment.