Skip to content

Commit

Permalink
Merge pull request #32 from dingwpmz/master
Browse files Browse the repository at this point in the history
修复登录时不指定-D参数时报错:MyCATApache/Mycat2#28
  • Loading branch information
fynwin authored Jul 24, 2017
2 parents 359fe4a + 48af64e commit 5553a18
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 17 deletions.
12 changes: 12 additions & 0 deletions Mycat-Core/src/main/java/io/mycat/SQLEngineCtx.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ protected Map<Object,Object> initialValue() {
*/
private Map<String,SchemaBean> mycatSchemaMap=new HashMap<String,SchemaBean>();

/**
* 默认Schema,取配置文件种第一个Schema
*/
private SchemaBean defaultSchemaBean;

public SQLCommandHandler getNomalSchemaSQLCmdHandler()
{
return normalSchemaSQLCmdHandler;
Expand Down Expand Up @@ -151,6 +156,9 @@ protected void addMySQLReplicatSet(final MySQLReplicatSet repSet) {

protected void addSchemaBean(SchemaBean schemaBean)
{
if(defaultSchemaBean == null ) { // call by MycatCore,在配置文件加载时初始化
defaultSchemaBean = schemaBean;
}
this.mycatSchemaMap.put(schemaBean.getName(), schemaBean);
}

Expand All @@ -159,6 +167,10 @@ public SchemaBean getMycatSchema(String schema)
return this.mycatSchemaMap.get(schema);
}

public SchemaBean getDefaultMycatSchema() {
return this.defaultSchemaBean;
}


public Object getCurrentContext(Object key) {
Map<Object,Object> map = currentContext.get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ public void transfer(MySQLConnection in, boolean isTransferLastPacket,boolean tr

//同步前后端状态
frontConn.setNextState(backendConn.getNextState());
// if(frontConn.getNextNetworkState() == null ) {
// frontConn.setNextNetworkState(NoReadAndWriteState.INSTANCE);
// }

//将buffer 后端buffer 共享给前端
MycatByteBuffer frontdatabuffer = frontConn.getDataBuffer();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import io.mycat.SQLEngineCtx;
import io.mycat.backend.MySQLBackendConnection;
import io.mycat.engine.ErrorCode;
import io.mycat.front.MySQLFrontConnection;
Expand All @@ -14,6 +15,7 @@
import io.mycat.net2.states.ClosingState;
import io.mycat.net2.states.ReadWaitingState;
import io.mycat.util.CharsetUtil;
import io.mycat.util.StringUtil;

/**
* 认证状态
Expand Down Expand Up @@ -80,7 +82,9 @@ private boolean success(MySQLFrontConnection con, AuthPacket auth) throws IOExce
LOGGER.debug("charset = {}, charsetIndex = {}", charset, charsetIndex);
con.setCharset(charsetIndex, charset);

if (!con.setFrontSchema(auth.database)) {
String db = StringUtil.isEmpty(auth.database)
? SQLEngineCtx.INSTANCE().getDefaultMycatSchema().getName() : auth.database;
if (!con.setFrontSchema(db)) {
final String errmsg = "No Mycat Schema defined: " + auth.database;
LOGGER.debug(errmsg);
con.writeErrMessage(ErrorCode.ER_BAD_DB_ERROR,"42000".getBytes(), errmsg);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
package io.mycat.sqlcache;

import java.io.IOException;
import java.util.ArrayList;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import io.mycat.NewSQLContext;
import io.mycat.SQLContext;

import io.mycat.SQLEngineCtx;
import io.mycat.backend.MySQLBackendConnection;
import io.mycat.backend.MySQLDataSource;
Expand Down Expand Up @@ -60,8 +65,11 @@ public void cacheSQLResult(NewSQLContext sqlContext, BigSQLResult bigSQLResult,
* cache-time=xxx auto-refresh=true access-count=5000
*/
String realSQL = sqlContext.getRealSQL(0);
// String key = "" + murmur3_32().hashUnencodedChars(realSQL);
Keyer<String, BigSQLResult> keyer = new Keyer<String, BigSQLResult>();

String key = "" ; // 屏蔽错误
// + murmur3_32().hashUnencodedChars(realSQL);
Keyer<String,BigSQLResult> keyer = new Keyer<String,BigSQLResult>();

keyer.setSql(realSQL);
// keyer.setKey(key);
keyer.setValue(bigSQLResult);
Expand All @@ -80,9 +88,10 @@ public void cacheSQLResult(NewSQLContext sqlContext, BigSQLResult bigSQLResult,
* @return
*/
public BigSQLResult getSQLResult(String sql) {
// String key = "" + murmur3_32().hashUnencodedChars(sql);
// return sqlResultCacheImp.get(key);
return null;

String key = ""; //+ murmur3_32().hashUnencodedChars(sql);
return sqlResultCacheImp.get(key);

}


Expand All @@ -93,8 +102,9 @@ public BigSQLResult getSQLResult(String sql) {
*/
public void remove(String sql) {

// String key = "" + murmur3_32().hashUnencodedChars(sql);
String key = "";

String key = "" ;//+ murmur3_32().hashUnencodedChars(sql);

sqlResultCacheImp.remove(key);
}

Expand All @@ -121,9 +131,11 @@ public boolean processHintSQL(MySQLFrontConnection frontCon, NewSQLContext sqlCo
String realSql = sqlContext.getRealSQL(0);
BigSQLResult sqlResultCache = getSQLResult(realSql);

if (sqlResultCache != null) {
// LOGGER.error(realSql + ":====>>>> Use Local Cache SQL Resuls");
sqlResultCacheDirectClient(frontCon, sqlResultCache);

if (sqlResultCache != null){
LOGGER.error(realSql + ":====>>>> Use Local Cache SQL Resuls");
//sqlResultCacheDirectClient(frontCon,sqlResultCache);

return true;
} else {
/**从后端拉取数据进行缓存*/
Expand All @@ -143,7 +155,7 @@ public boolean processHintSQL(MySQLFrontConnection frontCon, NewSQLContext sqlCo
*/
MySQLBackendConnection existCon = null;
UserSession session = frontCon.getSession();
ArrayList<MySQLBackendConnection> allBackCons = session.getBackendCons();
ArrayList<MySQLBackendConnection> allBackCons = null; //session.getBackendCons();
if (!allBackCons.isEmpty()) {
existCon = allBackCons.get(0);
}
Expand All @@ -165,7 +177,8 @@ public boolean processHintSQL(MySQLFrontConnection frontCon, NewSQLContext sqlCo
* 如果该sql对应后端db,没有连接池,则创建连接池部分
*/
final MySQLBackendConnection newCon = null;
// datas.getConnection(frontCon.getReactor(), dnBean.getDatabase(), true, null);

// datas.getConnection(frontCon.getReactor(), dnBean.getDatabase(), true, null);


/**很关键的设置前端front 与 backend session*/
Expand Down Expand Up @@ -194,9 +207,11 @@ public boolean processHintSQL(MySQLFrontConnection frontCon, NewSQLContext sqlCo
/**
* 否则直接写到后端即可
*/
// command.arg = realSql.getBytes(existCon.getCharset());
// existCon.getWriteDataBuffer().putBytes(command.write(existCon));
// existCon.enableWrite(false);

command.arg = realSql.getBytes(existCon.getCharset());
// existCon.getWriteDataBuffer().putBytes(command.write(existCon));
// existCon.enableWrite(false);

/**设置后端连接池结果集处理handler,sqlResultCache缓存结果集类*/
existCon.setUserCallback(new SQLResCacheHintHandler(sqlContext, sqlResultCache));
}
Expand Down
4 changes: 4 additions & 0 deletions Mycat-Core/src/main/java/io/mycat/util/StringUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,10 @@ public final static String dumpAsHex(final ByteBuffer buffer, final int offset,
return (dumpAsHex(new ByteBufferGetable(buffer), offset, length));
}

public final static boolean isEmpty(String str) {
return str == null || str == "";
}

// public final static String dumpAsHex(final ConDataBuffer buffer){
// return (dumpAsHex(buffer, 0, buffer.getWritePos()));
// }
Expand Down

0 comments on commit 5553a18

Please sign in to comment.