2017-07-19 12:50:21,689 [INFO ][main] total resouces of dataHost localhost1 is :2 (io.mycat.backend.datasource.PhysicalDBPool:PhysicalDBPool.java:100)
2017-07-19 12:50:21,749 [INFO ][main] create layer cache pool TableID2DataNodeCache of type encache ,default cache size 10000 ,default expire seconds18000 (io.mycat.cache.CacheService:CacheService.java:125)
2017-07-19 12:50:21,750 [INFO ][main] create child Cache: TESTDB_ORDERS for layered cache TableID2DataNodeCache, size 50000, expire seconds 18000 (io.mycat.cache.DefaultLayedCachePool:DefaultLayedCachePool.java:80)
2017-07-19 12:50:23,129 [INFO ][main] dyna class load from D:\workspace-sts-3.8.4.RELEASE\mycat\src\main\catlet,and auto check for class file modified every 60 seconds (io.mycat.config.classloader.DynaClassLoader:DynaClassLoader.java:34)
2017-07-19 12:50:23,129 [INFO ][main] =============================================== (io.mycat.MycatServer:MycatServer.java:258)
2017-07-19 12:50:23,129 [INFO ][main] MyCat is ready to startup ... (io.mycat.MycatServer:MycatServer.java:259)
2017-07-19 12:50:23,129 [INFO ][main] Startup processors ...,total processors:4,aio thread pool size:8
each process allocated socket buffer pool bytes ,a page size:2097152 a page's chunk number(PageSize/ChunkSize) is:512 buffer page's number is:80 (io.mycat.MycatServer:MycatServer.java:271)
2017-07-19 12:50:23,129 [INFO ][main] sysconfig params:SystemConfig [processorBufferLocalPercent=100, frontSocketSoRcvbuf=1048576, frontSocketSoSndbuf=4194304, backSocketSoRcvbuf=4194304, backSocketSoSndbuf=1048576, frontSocketNoDelay=1, backSocketNoDelay=1, maxStringLiteralLength=65535, frontWriteQueueSize=2048, bindIp=0.0.0.0, serverPort=8066, managerPort=9066, charset=utf8, processors=4, processorExecutor=8, timerExecutor=2, managerExecutor=2, idleTimeout=1800000, catletClassCheckSeconds=60, sqlExecuteTimeout=300, processorCheckPeriod=1000, dataNodeIdleCheckPeriod=300000, dataNodeHeartbeatPeriod=10000, clusterHeartbeatUser=_HEARTBEAT_USER_, clusterHeartbeatPass=_HEARTBEAT_PASS_, clusterHeartbeatPeriod=5000, clusterHeartbeatTimeout=10000, clusterHeartbeatRetry=10, txIsolation=3, parserCommentVersion=50148, sqlRecordCount=10, bufferPoolPageSize=2097152, bufferPoolChunkSize=4096, bufferPoolPageNumber=80, maxResultSet=524288, bigResultSizeSqlCount=10, bufferUsagePercent=80, flowControlRejectStrategy=0, clearBigSqLResultSetMapMs=600000, defaultMaxLimit=100, sequnceHandlerType=2, sqlInterceptor=io.mycat.server.interceptor.impl.DefaultSqlInterceptor, sqlInterceptorType=select, sqlInterceptorFile=D:\workspace-sts-3.8.4.RELEASE\mycat/logs/sql.txt, mutiNodeLimitType=0, mutiNodePatchSize=100, defaultSqlParser=druidparser, usingAIO=0, packetHeaderSize=4, maxPacketSize=16777216, mycatNodeId=1] (io.mycat.MycatServer:MycatServer.java:272)
2017-07-19 12:50:23,243 [INFO ][main] useOffHeapForMerge = 1 (io.mycat.memory.MyCatMemory:MyCatMemory.java:53)
2017-07-19 12:50:23,243 [INFO ][main] memoryPageSize = 1m (io.mycat.memory.MyCatMemory:MyCatMemory.java:54)
2017-07-19 12:50:23,243 [INFO ][main] spillsFileBufferSize = 1k (io.mycat.memory.MyCatMemory:MyCatMemory.java:55)
2017-07-19 12:50:23,243 [INFO ][main] useStreamOutput = 0 (io.mycat.memory.MyCatMemory:MyCatMemory.java:56)
2017-07-19 12:50:23,243 [INFO ][main] systemReserveMemorySize = 384m (io.mycat.memory.MyCatMemory:MyCatMemory.java:57)
2017-07-19 12:50:23,263 [INFO ][main] totalNetWorkBufferSize = 160MB (io.mycat.memory.MyCatMemory:MyCatMemory.java:58)
2017-07-19 12:50:23,263 [INFO ][main] dataNodeSortedTempDir = D:\workspace-sts-3.8.4.RELEASE\mycat (io.mycat.memory.MyCatMemory:MyCatMemory.java:59)
2017-07-19 12:50:23,279 [INFO ][main] mycat.memory.offHeap.size: 1010MB (io.mycat.memory.MyCatMemory:MyCatMemory.java:122)
2017-07-19 12:50:23,295 [INFO ][main] using nio network handler (io.mycat.MycatServer:MycatServer.java:373)
2017-07-19 12:50:24,659 [INFO ][main] $_MyCatManager is started and listening on 9066 (io.mycat.MycatServer:MycatServer.java:389)
2017-07-19 12:50:24,659 [INFO ][main] $_MyCatServer is started and listening on 8066 (io.mycat.MycatServer:MycatServer.java:393)
2017-07-19 12:50:24,660 [INFO ][main] =============================================== (io.mycat.MycatServer:MycatServer.java:395)
2017-07-19 12:50:24,660 [INFO ][main] Initialize dataHost ... (io.mycat.MycatServer:MycatServer.java:399)
2017-07-19 12:50:24,660 [INFO ][main] init backend myqsl source ,create connections total 10 for hostM1 index :0 (io.mycat.backend.datasource.PhysicalDBPool:PhysicalDBPool.java:294)
2017-07-19 12:50:24,661 [INFO ][main] no ilde connection in pool,create new connection for hostM1 of schema n (io.mycat.backend.datasource.PhysicalDatasource:PhysicalDatasource.java:413)
2017-07-19 12:50:24,662 [INFO ][main] no ilde connection in pool,create new connection for hostM1 of schema m (io.mycat.backend.datasource.PhysicalDatasource:PhysicalDatasource.java:413)
2017-07-19 12:50:24,662 [INFO ][main] no ilde connection in pool,create new connection for hostM1 of schema n (io.mycat.backend.datasource.PhysicalDatasource:PhysicalDatasource.java:413)
2017-07-19 12:50:24,662 [INFO ][main] no ilde connection in pool,create new connection for hostM1 of schema m (io.mycat.backend.datasource.PhysicalDatasource:PhysicalDatasource.java:413)
2017-07-19 12:50:24,665 [INFO ][main] no ilde connection in pool,create new connection for hostM1 of schema n (io.mycat.backend.datasource.PhysicalDatasource:PhysicalDatasource.java:413)
2017-07-19 12:50:24,665 [INFO ][main] no ilde connection in pool,create new connection for hostM1 of schema m (io.mycat.backend.datasource.PhysicalDatasource:PhysicalDatasource.java:413)
2017-07-19 12:50:24,666 [INFO ][main] no ilde connection in pool,create new connection for hostM1 of schema n (io.mycat.backend.datasource.PhysicalDatasource:PhysicalDatasource.java:413)
2017-07-19 12:50:24,666 [INFO ][main] no ilde connection in pool,create new connection for hostM1 of schema m (io.mycat.backend.datasource.PhysicalDatasource:PhysicalDatasource.java:413)
2017-07-19 12:50:24,666 [INFO ][main] no ilde connection in pool,create new connection for hostM1 of schema n (io.mycat.backend.datasource.PhysicalDatasource:PhysicalDatasource.java:413)
2017-07-19 12:50:24,666 [INFO ][main] no ilde connection in pool,create new connection for hostM1 of schema m (io.mycat.backend.datasource.PhysicalDatasource:PhysicalDatasource.java:413)
2017-07-19 12:50:25,547 [INFO ][$_NIOREACTOR-3-RW] connected successfuly MySQLConnection [id=7, lastTime=1500439825547, user=root, schema=m, old shema=m, borrowed=true, fromSlaveDB=false, threadId=26, charset=latin1, txIsolation=3, autocommit=true, attachment=null, respHandler=null, host=10.0.0.129, port=3306, statusSync=null, writeQueue=0, modifiedSQLExecuted=false] (io.mycat.backend.mysql.nio.handler.GetConnectionHandler:GetConnectionHandler.java:67)
2017-07-19 12:50:25,547 [INFO ][$_NIOREACTOR-1-RW] connected successfuly MySQLConnection [id=1, lastTime=1500439825547, user=root, schema=m, old shema=m, borrowed=true, fromSlaveDB=false, threadId=24, charset=latin1, txIsolation=3, autocommit=true, attachment=null, respHandler=null, host=10.0.0.129, port=3306, statusSync=null, writeQueue=0, modifiedSQLExecuted=false] (io.mycat.backend.mysql.nio.handler.GetConnectionHandler:GetConnectionHandler.java:67)
2017-07-19 12:50:25,548 [INFO ][$_NIOREACTOR-2-RW] connected successfuly MySQLConnection [id=6, lastTime=1500439825547, user=root, schema=n, old shema=n, borrowed=true, fromSlaveDB=false, threadId=25, charset=latin1, txIsolation=3, autocommit=true, attachment=null, respHandler=null, host=10.0.0.129, port=3306, statusSync=null, writeQueue=0, modifiedSQLExecuted=false] (io.mycat.backend.mysql.nio.handler.GetConnectionHandler:GetConnectionHandler.java:67)
2017-07-19 12:50:25,793 [INFO ][$_NIOREACTOR-2-RW] connected successfuly MySQLConnection [id=2, lastTime=1500439825793, user=root, schema=m, old shema=m, borrowed=true, fromSlaveDB=false, threadId=30, charset=latin1, txIsolation=3, autocommit=true, attachment=null, respHandler=null, host=10.0.0.129, port=3306, statusSync=null, writeQueue=0, modifiedSQLExecuted=false] (io.mycat.backend.mysql.nio.handler.GetConnectionHandler:GetConnectionHandler.java:67)
2017-07-19 12:50:25,793 [INFO ][$_NIOREACTOR-3-RW] connected successfuly MySQLConnection [id=3, lastTime=1500439825793, user=root, schema=m, old shema=m, borrowed=true, fromSlaveDB=false, threadId=28, charset=latin1, txIsolation=3, autocommit=true, attachment=null, respHandler=null, host=10.0.0.129, port=3306, statusSync=null, writeQueue=0, modifiedSQLExecuted=false] (io.mycat.backend.mysql.nio.handler.GetConnectionHandler:GetConnectionHandler.java:67)
2017-07-19 12:50:25,795 [INFO ][$_NIOREACTOR-0-RW] connected successfuly MySQLConnection [id=8, lastTime=1500439825795, user=root, schema=n, old shema=n, borrowed=true, fromSlaveDB=false, threadId=31, charset=latin1, txIsolation=3, autocommit=true, attachment=null, respHandler=null, host=10.0.0.129, port=3306, statusSync=null, writeQueue=0, modifiedSQLExecuted=false] (io.mycat.backend.mysql.nio.handler.GetConnectionHandler:GetConnectionHandler.java:67)
2017-07-19 12:50:25,795 [INFO ][$_NIOREACTOR-1-RW] connected successfuly MySQLConnection [id=5, lastTime=1500439825795, user=root, schema=m, old shema=m, borrowed=true, fromSlaveDB=false, threadId=27, charset=latin1, txIsolation=3, autocommit=true, attachment=null, respHandler=null, host=10.0.0.129, port=3306, statusSync=null, writeQueue=0, modifiedSQLExecuted=false] (io.mycat.backend.mysql.nio.handler.GetConnectionHandler:GetConnectionHandler.java:67)
2017-07-19 12:50:25,796 [INFO ][$_NIOREACTOR-0-RW] connected successfuly MySQLConnection [id=4, lastTime=1500439825796, user=root, schema=n, old shema=n, borrowed=true, fromSlaveDB=false, threadId=29, charset=latin1, txIsolation=3, autocommit=true, attachment=null, respHandler=null, host=10.0.0.129, port=3306, statusSync=null, writeQueue=0, modifiedSQLExecuted=false] (io.mycat.backend.mysql.nio.handler.GetConnectionHandler:GetConnectionHandler.java:67)
2017-07-19 12:50:25,808 [INFO ][$_NIOREACTOR-1-RW] connected successfuly MySQLConnection [id=9, lastTime=1500439825808, user=root, schema=n, old shema=n, borrowed=true, fromSlaveDB=false, threadId=32, charset=latin1, txIsolation=3, autocommit=true, attachment=null, respHandler=null, host=10.0.0.129, port=3306, statusSync=null, writeQueue=0, modifiedSQLExecuted=false] (io.mycat.backend.mysql.nio.handler.GetConnectionHandler:GetConnectionHandler.java:67)
2017-07-19 12:50:25,810 [INFO ][$_NIOREACTOR-2-RW] connected successfuly MySQLConnection [id=10, lastTime=1500439825810, user=root, schema=n, old shema=n, borrowed=true, fromSlaveDB=false, threadId=33, charset=latin1, txIsolation=3, autocommit=true, attachment=null, respHandler=null, host=10.0.0.129, port=3306, statusSync=null, writeQueue=0, modifiedSQLExecuted=false] (io.mycat.backend.mysql.nio.handler.GetConnectionHandler:GetConnectionHandler.java:67)
2017-07-19 12:50:25,876 [INFO ][main] init result :finished 10 success 10 target count:10 (io.mycat.backend.datasource.PhysicalDBPool:PhysicalDBPool.java:319)
2017-07-19 12:50:25,876 [INFO ][main] localhost1 index:0 init success (io.mycat.backend.datasource.PhysicalDBPool:PhysicalDBPool.java:265)
2017-07-19 12:50:25,876 [INFO ][main] save DataHost index localhost1 cur index 0 (io.mycat.MycatServer:MycatServer.java:557)
MyCAT Server startup successfully. see logs in logs/mycat.log
2017-07-19 12:50:28,061 [INFO ][Timer1] create connections ,because idle connection not enough ,cur is 0, minCon is 10 for hostS2 (io.mycat.backend.datasource.PhysicalDatasource:PhysicalDatasource.java:299)
2017-07-19 12:50:28,076 [INFO ][Timer1] no ilde connection in pool,create new connection for hostS2 of schema n (io.mycat.backend.datasource.PhysicalDatasource:PhysicalDatasource.java:413)
2017-07-19 12:50:28,293 [INFO ][$_NIOREACTOR-3-RW] connectionAcquired MySQLConnection [id=11, lastTime=1500439828275, user=root, schema=n, old shema=n, borrowed=false, fromSlaveDB=true, threadId=22, charset=latin1, txIsolation=3, autocommit=true, attachment=null, respHandler=null, host=10.0.0.128, port=3306, statusSync=null, writeQueue=0, modifiedSQLExecuted=false] (io.mycat.backend.mysql.nio.handler.NewConnectionRespHandler:NewConnectionRespHandler.java:45)
2017-07-19 12:50:28,319 [INFO ][$_NIOREACTOR-2-RW] connectionAcquired MySQLConnection [id=14, lastTime=1500439828316, user=root, schema=m, old shema=m, borrowed=false, fromSlaveDB=true, threadId=25, charset=latin1, txIsolation=3, autocommit=true, attachment=null, respHandler=null, host=10.0.0.128, port=3306, statusSync=null, writeQueue=0, modifiedSQLExecuted=false] (io.mycat.backend.mysql.nio.handler.NewConnectionRespHandler:NewConnectionRespHandler.java:45)
2017-07-19 12:50:28,322 [INFO ][$_NIOREACTOR-0-RW] connectionAcquired MySQLConnection [id=12, lastTime=1500439828316, user=root, schema=n, old shema=n, borrowed=false, fromSlaveDB=true, threadId=23, charset=latin1, txIsolation=3, autocommit=true, attachment=null, respHandler=null, host=10.0.0.128, port=3306, statusSync=null, writeQueue=0, modifiedSQLExecuted=false] (io.mycat.backend.mysql.nio.handler.NewConnectionRespHandler:NewConnectionRespHandler.java:45)
2017-07-19 12:53:16,500 [INFO ][$_NIOREACTOR-3-RW] ServerConnection [id=1, schema=null, host=192.168.1.4, user=root,txIsolation=3, autocommit=true, schema=null]'root' login success (io.mycat.net.handler.FrontendAuthenticator:FrontendAuthenticator.java:194)
2017-07-19 12:53:17,663 [INFO ][$_NIOREACTOR-3-RW] close connection,reason:quit cmd ,ServerConnection [id=1, schema=null, host=192.168.1.4, user=root,txIsolation=3, autocommit=true, schema=null] (io.mycat.net.AbstractConnection:AbstractConnection.java:508)
2017-07-19 12:53:20,226 [INFO ][$_NIOREACTOR-0-RW] ServerConnection [id=2, schema=null, host=192.168.1.4, user=root,txIsolation=3, autocommit=true, schema=null]'root' login success (io.mycat.net.handler.FrontendAuthenticator:FrontendAuthenticator.java:194)
2017-07-19 12:53:21,555 [INFO ][$_NIOREACTOR-1-RW] ServerConnection [id=3, schema=null, host=192.168.1.4, user=root,txIsolation=3, autocommit=true, schema=null]'root' login success (io.mycat.net.handler.FrontendAuthenticator:FrontendAuthenticator.java:194)
2017-07-19 12:53:24,426 [INFO ][$_NIOREACTOR-1-RW] close connection,reason:quit cmd ,ServerConnection [id=3, schema=TESTDB, host=192.168.1.4, user=root,txIsolation=3, autocommit=true, schema=TESTDB] (io.mycat.net.AbstractConnection:AbstractConnection.java:508)
2017-07-19 12:53:24,427 [INFO ][$_NIOREACTOR-0-RW] close connection,reason:quit cmd ,ServerConnection [id=2, schema=null, host=192.168.1.4, user=root,txIsolation=3, autocommit=true, schema=null] (io.mycat.net.AbstractConnection:AbstractConnection.java:508)
2017-07-19 12:53:25,222 [INFO ][$_NIOREACTOR-2-RW] ServerConnection [id=4, schema=null, host=192.168.1.4, user=root,txIsolation=3, autocommit=true, schema=null]'root' login success (io.mycat.net.handler.FrontendAuthenticator:FrontendAuthenticator.java:194)
2017-07-19 12:53:26,713 [INFO ][$_NIOREACTOR-3-RW] ServerConnection [id=5, schema=null, host=192.168.1.4, user=root,txIsolation=3, autocommit=true, schema=null]'root' login success (io.mycat.net.handler.FrontendAuthenticator:FrontendAuthenticator.java:194)
2017-07-19 12:55:28,039 [INFO ][Timer0] create connections ,because idle connection not enough ,cur is 5, minCon is 10 for hostM1 (io.mycat.backend.datasource.PhysicalDatasource:PhysicalDatasource.java:299)
2017-07-19 12:55:28,040 [INFO ][Timer0] create connections ,because idle connection not enough ,cur is 4, minCon is 10 for hostS2 (io.mycat.backend.datasource.PhysicalDatasource:PhysicalDatasource.java:299)
2017-07-19 12:55:28,143 [INFO ][$_NIOREACTOR-0-RW] connectionAcquired MySQLConnection [id=15, lastTime=1500440128137, user=root, schema=m, old shema=m, borrowed=false, fromSlaveDB=true, threadId=26, charset=latin1, txIsolation=3, autocommit=true, attachment=null, respHandler=null, host=10.0.0.128, port=3306, statusSync=null, writeQueue=0, modifiedSQLExecuted=false] (io.mycat.backend.mysql.nio.handler.NewConnectionRespHandler:NewConnectionRespHandler.java:45)
2017-07-19 12:55:28,153 [INFO ][$_NIOREACTOR-2-RW] connectionAcquired MySQLConnection [id=17, lastTime=1500440128137, user=root, schema=n, old shema=n, borrowed=false, fromSlaveDB=true, threadId=27, charset=latin1, txIsolation=3, autocommit=true, attachment=null, respHandler=null, host=10.0.0.128, port=3306, statusSync=null, writeQueue=0, modifiedSQLExecuted=false] (io.mycat.backend.mysql.nio.handler.NewConnectionRespHandler:NewConnectionRespHandler.java:45)
2017-07-19 12:55:28,172 [INFO ][$_NIOREACTOR-1-RW] connectionAcquired MySQLConnection [id=16, lastTime=1500440128157, user=root, schema=n, old shema=n, borrowed=false, fromSlaveDB=false, threadId=34, charset=latin1, txIsolation=3, autocommit=true, attachment=null, respHandler=null, host=10.0.0.129, port=3306, statusSync=null, writeQueue=0, modifiedSQLExecuted=false] (io.mycat.backend.mysql.nio.handler.NewConnectionRespHandler:NewConnectionRespHandler.java:45)
2017-07-19 13:00:28,040 [INFO ][Timer0] too many ilde cons ,close some for datasouce hostM1 (io.mycat.backend.datasource.PhysicalDatasource:PhysicalDatasource.java:280)
2017-07-19 13:00:28,043 [INFO ][Timer0] close connection,reason:too many idle con ,MySQLConnection [id=1, lastTime=1500440128058, user=root, schema=m, old shema=m, borrowed=false, fromSlaveDB=false, threadId=24, charset=latin1, txIsolation=3, autocommit=true, attachment=null, respHandler=null, host=10.0.0.129, port=3306, statusSync=null, writeQueue=0, modifiedSQLExecuted=false] (io.mycat.net.AbstractConnection:AbstractConnection.java:508)
2017-07-19 13:00:28,044 [INFO ][Timer0] create connections ,because idle connection not enough ,cur is 5, minCon is 10 for hostS2 (io.mycat.backend.datasource.PhysicalDatasource:PhysicalDatasource.java:299)
2017-07-19 13:00:28,063 [INFO ][$_NIOREACTOR-3-RW] connectionAcquired MySQLConnection [id=18, lastTime=1500440428058, user=root, schema=n, old shema=n, borrowed=false, fromSlaveDB=true, threadId=28, charset=latin1, txIsolation=3, autocommit=true, attachment=null, respHandler=null, host=10.0.0.128, port=3306, statusSync=null, writeQueue=0, modifiedSQLExecuted=false] (io.mycat.backend.mysql.nio.handler.NewConnectionRespHandler:NewConnectionRespHandler.java:45)
2017-07-19 13:05:28,044 [INFO ][Timer0] create connections ,because idle connection not enough ,cur is 6, minCon is 10 for hostM1 (io.mycat.backend.datasource.PhysicalDatasource:PhysicalDatasource.java:299)
2017-07-19 13:05:28,044 [INFO ][Timer0] create connections ,because idle connection not enough ,cur is 5, minCon is 10 for hostS2 (io.mycat.backend.datasource.PhysicalDatasource:PhysicalDatasource.java:299)
2017-07-19 13:05:28,119 [INFO ][$_NIOREACTOR-0-RW] connectionAcquired MySQLConnection [id=19, lastTime=1500440728101, user=root, schema=n, old shema=n, borrowed=false, fromSlaveDB=false, threadId=35, charset=latin1, txIsolation=3, autocommit=true, attachment=null, respHandler=null, host=10.0.0.129, port=3306, statusSync=null, writeQueue=0, modifiedSQLExecuted=false] (io.mycat.backend.mysql.nio.handler.NewConnectionRespHandler:NewConnectionRespHandler.java:45)
2017-07-19 13:05:28,120 [INFO ][$_NIOREACTOR-1-RW] connectionAcquired MySQLConnection [id=20, lastTime=1500440728101, user=root, schema=n, old shema=n, borrowed=false, fromSlaveDB=true, threadId=29, charset=latin1, txIsolation=3, autocommit=true, attachment=null, respHandler=null, host=10.0.0.128, port=3306, statusSync=null, writeQueue=0, modifiedSQLExecuted=false] (io.mycat.backend.mysql.nio.handler.NewConnectionRespHandler:NewConnectionRespHandler.java:45)
IDE异常处理
在配置过程中遇到:Archive for required library: 'D:/DEVELOPERS/maven/apache-maven-3.5.0/repository/mysql/mysql-connector-java/5.1.35/mysql-connector-java-5.1.35.jar' in project 'mycat' cannot be read or is not a valid ZIP file mycat Build path Build Path Problem
处理方法:删除maven下载目录,编辑pom.xml使之重新下载jar包。
Mycat开发示例修改源码支持按天分库
这里我们只需要修改
标签的subTables属性的封装就可以实现。
Java源码修改
TableConfig.java 修改代码部分:
public TableConfig(String name, String primaryKey, boolean autoIncrement,boolean needAddLimit, int tableType,
String dataNode,Set dbType, RuleConfig rule, boolean ruleRequired,
TableConfig parentTC, boolean isChildTable, String joinKey,
String parentKey,String subTables) {
if (name == null) {
throw new IllegalArgumentException("table name is null");
} else if (dataNode == null) {
throw new IllegalArgumentException("dataNode name is null");
}
this.primaryKey = primaryKey;
this.autoIncrement = autoIncrement;
this.needAddLimit=needAddLimit;
this.tableType = tableType;
this.dbTypes=dbType;
if (ruleRequired && rule == null) {
throw new IllegalArgumentException("ruleRequired but rule is null");
}
this.name = name.toUpperCase();
String theDataNodes[] = SplitUtil.split(dataNode, ',', '$', '-');
if (theDataNodes == null || theDataNodes.length <= 0) {
throw new IllegalArgumentException("invalid table dataNodes: " + dataNode);
}
dataNodes = new ArrayList(theDataNodes.length);
for (String dn : theDataNodes) {
dataNodes.add(dn);
}
if(subTables!=null && !subTables.equals("")){
// =====新增按日分表策略====start====
String str=subTables.substring(subTables.indexOf("$")+1, subTables.length());
String startChar="(";
String splitChar=",";
String endChar=")";
boolean valid=str.contains(startChar)&&str.contains(splitChar)&&str.contains(endChar);
// =====新增按日分表策略====end====
if(!valid){
// 原始按顺序分表方式
String sTables[] = SplitUtil.split(subTables, ',', '$', '-');
if (sTables == null || sTables.length <= 0) {
throw new IllegalArgumentException("invalid table subTables");
}
this.distTables = new ArrayList(sTables.length);
for (String table : sTables) {
distTables.add(table);
}
}else{
// 按日分表方式(表需要自己创建好)
str=str.substring(1, str.length()-1);
String [] strDates=str.split(",");
if(strDates.length!=2) {
throw new IllegalArgumentException("invalid table subTables:array's length is little than 2 ,you should set array like $(20170717,20180716)");
}
String dateStart=strDates[0];//开始日期
String dateEnd=strDates[1];// 结束日期
if(dateStart.equals(dateEnd)){
throw new IllegalArgumentException("invalid table subTables:array's start date can't be equal with end date,you should set array like $(20170717,20180716)");
}
String dateFormat="yyyyMMdd";
Date begin=null;
Date end=null;
try {
begin=DateUtils.parseDate(dateStart, dateFormat);
end=DateUtils.parseDate(dateEnd, dateFormat);
} catch (ParseException e) {
throw new IllegalArgumentException("invalid table subTables:array's date format is incorrect,you should set array like $(20170717,20180716)");
}
// 生成对应的按日期表集合
List dates=DateUtils.getBetweenDates(begin, end);
this.distTables = new ArrayList(dates.size());
String tablePrex=subTables.substring(0, subTables.indexOf("$"));
for (Date date : dates) {
String table=tablePrex+DateUtils.getStrFormTime(dateFormat, date);
System.out.println(table);
distTables.add(table);
}
}
}else{
this.distTables = new ArrayList();
}
this.rule = rule;
this.partitionColumn = (rule == null) ? null : rule.getColumn();
partionKeyIsPrimaryKey=(partitionColumn==null)?primaryKey==null:partitionColumn.equals(primaryKey);
this.ruleRequired = ruleRequired;
this.childTable = isChildTable;
this.parentTC = parentTC;
this.joinKey = joinKey;
this.parentKey = parentKey;
if (parentTC != null) {
locateRTableKeySql = genLocateRootParentSQL();
secondLevel = (parentTC.parentTC == null);
} else {
locateRTableKeySql = null;
secondLevel = false;
}
}
日期工具类
DateUtils.java
package io.mycat.config.util;
import java.sql.Timestamp;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import org.apache.log4j.Logger;
public class DateUtils extends org.apache.commons.lang.time.DateUtils {
public static final String TIME_WITH_MINUTE_PATTERN = "HH:mm";
public static final long DAY_MILLI = 24 * 60 * 60 * 1000; // 一天的MilliSecond
// 取值范围:就是临界点包不包含等于
public final static int LEFT_OPEN_RIGHT_OPEN = 1;
public final static int LEFT_CLOSE_RIGHT_OPEN = 2;
public final static int LEFT_OPEN_RIGHT_CLOSE = 3;
public final static int LEFT_CLOSE_RIGHT_CLOSE = 4;
/**
* 比较日期的模式 --只比较日期,不比较时间
*/
public final static int COMP_MODEL_DATE = 1;
/**
* 比较日期的模式 --只比较时间,不比较日期
*/
public final static int COMP_MODEL_TIME = 2;
/**
* 比较日期的模式 --比较日期,也比较时间
*/
public final static int COMP_MODEL_DATETIME = 3;
private static Logger logger = Logger.getLogger(DateUtils.class);
/**
* 要用到的DATE Format的定义
*/
public static String DATE_FORMAT_DATEONLY = "yyyy-MM-dd"; // 年/月/日
public static String DATE_FORMAT_DATETIME = "yyyy-MM-dd HH:mm:ss"; // 年/月/日
public static SimpleDateFormat sdfDateTime = new SimpleDateFormat(DateUtils.DATE_FORMAT_DATETIME);
public static SimpleDateFormat sdfDateOnly = new SimpleDateFormat(DateUtils.DATE_FORMAT_DATEONLY);
public static final SimpleDateFormat formatTimestamp = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
public static final SimpleDateFormat SHORTDATEFORMAT = new SimpleDateFormat("yyyyMMdd");
public static final SimpleDateFormat SHORT_DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd");
public static final SimpleDateFormat LONG_DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
public static final SimpleDateFormat LONG_DATE_FORMAT_SSS = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
public static final SimpleDateFormat HMS_FORMAT = new SimpleDateFormat("HH:mm:ss");
/**
* 根据日期格式字符串解析日期字符串
*
* @param str
* 日期字符串
* @param parsePatterns
* 日期格式字符串
* @return 解析后日期
* @throws ParseException
*/
public static Date parseDate(String str, String parsePatterns) throws ParseException {
return parseDate(str, new String[] { parsePatterns });
}
/**
* 根据单位字段比较两个日期
*
* @param date
* 日期1
* @param otherDate
* 日期2
* @param withUnit
* 单位字段,从Calendar field取值
* @return 等于返回0值, 大于返回大于0的值 小于返回小于0的值
*/
public static int compareDate(Date date, Date otherDate, int withUnit) {
Calendar dateCal = Calendar.getInstance();
dateCal.setTime(date);
Calendar otherDateCal = Calendar.getInstance();
otherDateCal.setTime(otherDate);
switch (withUnit) {
case Calendar.YEAR:
dateCal.clear(Calendar.MONTH);
otherDateCal.clear(Calendar.MONTH);
case Calendar.MONTH:
dateCal.set(Calendar.DATE, 1);
otherDateCal.set(Calendar.DATE, 1);
case Calendar.DATE:
dateCal.set(Calendar.HOUR_OF_DAY, 0);
otherDateCal.set(Calendar.HOUR_OF_DAY, 0);
case Calendar.HOUR:
dateCal.clear(Calendar.MINUTE);
otherDateCal.clear(Calendar.MINUTE);
case Calendar.MINUTE:
dateCal.clear(Calendar.SECOND);
otherDateCal.clear(Calendar.SECOND);
case Calendar.SECOND:
dateCal.clear(Calendar.MILLISECOND);
otherDateCal.clear(Calendar.MILLISECOND);
case Calendar.MILLISECOND:
break;
default:
throw new IllegalArgumentException("withUnit 单位字段 " + withUnit + " 不合法!!");
}
return dateCal.compareTo(otherDateCal);
}
/**
* 根据单位字段比较两个时间
*
* @param date
* 时间1
* @param otherDate
* 时间2
* @param withUnit
* 单位字段,从Calendar field取值
* @return 等于返回0值, 大于返回大于0的值 小于返回小于0的值
*/
public static int compareTime(Date date, Date otherDate, int withUnit) {
Calendar dateCal = Calendar.getInstance();
dateCal.setTime(date);
Calendar otherDateCal = Calendar.getInstance();
otherDateCal.setTime(otherDate);
dateCal.clear(Calendar.YEAR);
dateCal.clear(Calendar.MONTH);
dateCal.set(Calendar.DATE, 1);
otherDateCal.clear(Calendar.YEAR);
otherDateCal.clear(Calendar.MONTH);
otherDateCal.set(Calendar.DATE, 1);
switch (withUnit) {
case Calendar.HOUR:
dateCal.clear(Calendar.MINUTE);
otherDateCal.clear(Calendar.MINUTE);
case Calendar.MINUTE:
dateCal.clear(Calendar.SECOND);
otherDateCal.clear(Calendar.SECOND);
case Calendar.SECOND:
dateCal.clear(Calendar.MILLISECOND);
otherDateCal.clear(Calendar.MILLISECOND);
case Calendar.MILLISECOND:
break;
default:
throw new IllegalArgumentException("withUnit 单位字段 " + withUnit + " 不合法!!");
}
return dateCal.compareTo(otherDateCal);
}
/**
* 获得当前的日期毫秒
*
* @return
*/
public static long nowTimeMillis() {
return System.currentTimeMillis();
}
/**
* 获得当前的时间戳
*
* @return
*/
public static Timestamp nowTimeStamp() {
return new Timestamp(nowTimeMillis());
}
/**
* yyyy-MM-dd 当前日期
*
*/
public static String getReqDate() {
return SHORTDATEFORMAT.format(new Date());
}
/**
* yyyy-MM-dd 传入日期
*
* @param date
* @return
*/
public static String getReqDate(Date date) {
return SHORT_DATE_FORMAT.format(date);
}
/**
* yyyyMMdd 传入日期
*
* @param date
* @return
*/
public static String getReqDateyyyyMMdd(Date date) {
return SHORTDATEFORMAT.format(date);
}
/**
* yyyy-MM-dd 传入的时间戳
*
* @param date
* @return
*/
public static String TimestampToDateStr(Timestamp tmp) {
return SHORT_DATE_FORMAT.format(tmp);
}
/**
* HH:mm:ss 当前时间
*
* @return
*/
public static String getReqTime() {
return HMS_FORMAT.format(new Date());
}
/**
* 得到时间戳格式字串
*
* @param date
* @return
*/
public static String getTimeStampStr(Date date) {
return LONG_DATE_FORMAT.format(date);
}
/**
* 得到长日期格式字串
*
* @return
*/
public static String getLongDateStr() {
return LONG_DATE_FORMAT.format(new Date());
}
public static String getLongDateStr(Timestamp time) {
return LONG_DATE_FORMAT.format(time);
}
/**
* 得到短日期格式字串
*
* @param date
* @return
*/
public static String getShortDateStr(Date date) {
return SHORT_DATE_FORMAT.format(date);
}
public static String getShortDateStr() {
return SHORT_DATE_FORMAT.format(new Date());
}
/**
* 计算 second 秒后的时间
*
* @param date
* @param second
* @return
*/
public static Date addSecond(Date date, int second) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
;
calendar.add(Calendar.SECOND, second);
return calendar.getTime();
}
/**
* 计算 minute 分钟后的时间
*
* @param date
* @param minute
* @return
*/
public static Date addMinute(Date date, int minute) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.add(Calendar.MINUTE, minute);
return calendar.getTime();
}
/**
* 计算 hour 小时后的时间
*
* @param date
* @param minute
* @return
*/
public static Date addHour(Date date, int hour) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.add(Calendar.HOUR, hour);
return calendar.getTime();
}
/**
* 得到day的起始时间点。
*
* @param date
* @return
*/
public static Date getDayStart(Date date) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.set(Calendar.HOUR_OF_DAY, 0);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.MILLISECOND, 0);
return calendar.getTime();
}
/**
* 得到day的终止时间点.
*
* @param date
* @return
*/
public static Date getDayEnd(Date date) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.set(Calendar.HOUR_OF_DAY, 0);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.MILLISECOND, 0);
calendar.add(Calendar.DAY_OF_MONTH, 1);
calendar.add(Calendar.MILLISECOND, -1);
return calendar.getTime();
}
/**
* 计算 day 天后的时间
*
* @param date
* @param day
* @return
*/
public static Date addDay(Date date, int day) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.add(Calendar.DAY_OF_MONTH, day);
return calendar.getTime();
}
/**
* 得到month的终止时间点.
*
* @param date
* @return
*/
public static Date getMonthEnd(Date date) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.set(Calendar.DAY_OF_MONTH, 1);
calendar.set(Calendar.HOUR_OF_DAY, 0);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.MILLISECOND, 0);
calendar.add(Calendar.MONTH, 1);
calendar.add(Calendar.MILLISECOND, -1);
return calendar.getTime();
}
public static Date addYear(Date date, int year) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.add(Calendar.DAY_OF_YEAR, 365 * year);
return calendar.getTime();
}
public static Timestamp strToTimestamp(String dateStr) {
return Timestamp.valueOf(dateStr);
}
public static Timestamp strToTimestamp(Date date) {
return Timestamp.valueOf(formatTimestamp.format(date));
}
public static Timestamp getCurTimestamp() {
return Timestamp.valueOf(formatTimestamp.format(new Date()));
}
/**
* 取得两个日期之间的日数
*
* @return t1到t2间的日数,如果t2 在 t1之后,返回正数,否则返回负数
*/
public static long daysBetween(java.sql.Timestamp t1, java.sql.Timestamp t2) {
return (t2.getTime() - t1.getTime()) / DAY_MILLI;
}
/**
* 返回java.sql.Timestamp型的SYSDATE
*
* @return java.sql.Timestamp型的SYSDATE
* @since 1.0
* @history
*/
public static java.sql.Timestamp getSysDateTimestamp() {
return new java.sql.Timestamp(System.currentTimeMillis());
}
/**
* 利用缺省的Date格式(YYYY/MM/DD)转换String到java.sql.Timestamp
*
* @param sDate
* Date string
* @return
* @since 1.0
* @history
*/
public static java.sql.Timestamp toSqlTimestamp(String sDate) {
if (sDate == null) {
return null;
}
if (sDate.length() != DateUtils.DATE_FORMAT_DATEONLY.length()
&& sDate.length() != DateUtils.DATE_FORMAT_DATETIME.length()) {
return null;
}
return toSqlTimestamp(sDate, sDate.length() == DateUtils.DATE_FORMAT_DATEONLY.length()
? DateUtils.DATE_FORMAT_DATEONLY : DateUtils.DATE_FORMAT_DATETIME);
}
/**
* 利用缺省的Date格式(YYYY/MM/DD hh:mm:ss)转化String到java.sql.Timestamp
*
* @param sDate
* Date string
* @param sFmt
* Date format DATE_FORMAT_DATEONLY/DATE_FORMAT_DATETIME
* @return
* @since 1.0
* @history
*/
public static java.sql.Timestamp toSqlTimestamp(String sDate, String sFmt) {
String temp = null;
if (sDate == null || sFmt == null) {
return null;
}
if (sDate.length() != sFmt.length()) {
return null;
}
if (sFmt.equals(DateUtils.DATE_FORMAT_DATETIME)) {
temp = sDate.replace('/', '-');
temp = temp + ".000000000";
} else if (sFmt.equals(DateUtils.DATE_FORMAT_DATEONLY)) {
temp = sDate.replace('/', '-');
temp = temp + " 00:00:00.000000000";
} else {
return null;
}
return java.sql.Timestamp.valueOf(temp);
}
/**
* 以YYYY/MM/DD HH24:MI:SS格式返回系统日期时间
*
* @return 系统日期时间
* @since 1.0
* @history
*/
public static String getSysDateTimeString() {
return toString(new java.util.Date(System.currentTimeMillis()), DateUtils.sdfDateTime);
}
/**
* 根据指定的Format转化java.util.Date到String
*
* @param dt
* java.util.Date instance
* @param sFmt
* Date format , DATE_FORMAT_DATEONLY or DATE_FORMAT_DATETIME
* @return
* @since 1.0
* @history
*/
public static String toString(java.util.Date dt, String sFmt) {
if (dt == null || sFmt == null || "".equals(sFmt)) {
return "";
}
return toString(dt, new SimpleDateFormat(sFmt));
}
/**
* 利用指定SimpleDateFormat instance转换java.util.Date到String
*
* @param dt
* java.util.Date instance
* @param formatter
* SimpleDateFormat Instance
* @return
* @since 1.0
* @history
*/
private static String toString(java.util.Date dt, SimpleDateFormat formatter) {
String sRet = null;
try {
sRet = formatter.format(dt).toString();
} catch (Exception e) {
logger.error(e);
sRet = null;
}
return sRet;
}
/**
* 转换java.sql.Timestamp到String,格式为YYYY/MM/DD HH24:MI
*
* @param dt
* java.sql.Timestamp instance
* @return
* @since 1.0
* @history
*/
public static String toSqlTimestampString2(java.sql.Timestamp dt) {
if (dt == null) {
return null;
}
String temp = toSqlTimestampString(dt, DateUtils.DATE_FORMAT_DATETIME);
return temp.substring(0, 16);
}
public static String toString(java.sql.Timestamp dt) {
return dt == null ? "" : toSqlTimestampString2(dt);
}
/**
* 根据指定的格式转换java.sql.Timestamp到String
*
* @param dt
* java.sql.Timestamp instance
* @param sFmt
* Date 格式,DATE_FORMAT_DATEONLY/DATE_FORMAT_DATETIME/
* DATE_FORMAT_SESSION
* @return
* @since 1.0
* @history
*/
public static String toSqlTimestampString(java.sql.Timestamp dt, String sFmt) {
String temp = null;
String out = null;
if (dt == null || sFmt == null) {
return null;
}
temp = dt.toString();
if (sFmt.equals(DateUtils.DATE_FORMAT_DATETIME) || // "YYYY/MM/DD
// HH24:MI:SS"
sFmt.equals(DateUtils.DATE_FORMAT_DATEONLY)) { // YYYY/MM/DD
temp = temp.substring(0, sFmt.length());
out = temp.replace('/', '-');
// }else if( sFmt.equals (DateUtils.DATE_FORMAT_SESSION ) ){
// //Session
// out =
// temp.substring(0,4)+temp.substring(5,7)+temp.substring(8,10);
// out += temp.substring(12,14) + temp.substring(15,17);
}
return out;
}
// 得到当前日期的星期
public static int getWeek() {
Calendar cal = Calendar.getInstance();
cal.setTime(new Date());
int w = cal.get(Calendar.DAY_OF_WEEK);
return w;
}
/**
* Timestamp 格式转换成yyyy-MM-dd timestampToSql(Timestamp 格式转换成yyyy-MM-dd)
*
* @param timestamp
* 时间
* @return createTimeStr yyyy-MM-dd 时间
* @Exception 异常对象
* @since V1.0
*/
public static String timestampToStringYMD(java.sql.Timestamp timestamp) {
SimpleDateFormat sdf = new SimpleDateFormat(DateUtils.DATE_FORMAT_DATEONLY);
String createTimeStr = sdf.format(timestamp);
return createTimeStr;
}
/**
* 判断一个时间是否在某个时间区间内
*
* @param now
* 目标时间
* @param start
* 时间区间开始
* @param end
* 时间区间结束
* @param model
* 区间模式
* @return 是否在区间内
*/
public static boolean isBetween(Date now, Date start, Date end, int model) {
return isBetween(now, start, end, model, LEFT_OPEN_RIGHT_OPEN);
}
/**
* 判断时间是否在制定的时间段之类
*
* @param date
* 需要判断的时间
* @param start
* 时间段的起始时间
* @param end
* 时间段的截止时间
* @param interModel
* 区间的模式
*
*
转:http://stackoverflow.com/questions/18145774/eclipse-an-error-occurred-while-filtering-resources
maven报错:
maven An error occurred while filtering resources
Maven -> Update Proje
在SVN服务控制台打开资源库“SVN无法读取current” ---摘自网络 写道 SVN无法读取current修复方法 Can't read file : End of file found
文件:repository/db/txn_current、repository/db/current
其中current记录当前最新版本号,txn_current记录版本库中版本