Skip to content

Commit

Permalink
Merge pull request #472 from songwie/master
Browse files Browse the repository at this point in the history
配置重构
  • Loading branch information
linzhiqiang0514 committed Sep 23, 2015
2 parents 44331b6 + 9d517e6 commit 04e2bde
Show file tree
Hide file tree
Showing 197 changed files with 3,051 additions and 3,269 deletions.
4 changes: 1 addition & 3 deletions conf/dnindex.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#update
#Wed Mar 12 17:02:13 CST 2014
localhost1=0
jdbclhost=0
#Tue Sep 22 15:07:18 CST 2015
jdbchost=0
8 changes: 4 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

<properties>
<app.encoding>UTF-8</app.encoding>
<!-- maven.build.timestamp.format>yyyyMMdd</maven.build.timestamp.format>
<!-- maven.build.timestamp.format>yyyyMMdd</maven.build.timestamp.format>
<buildNumber>${maven.build.timestamp}</buildNumber -->
<maven.build.timestamp.format>yyyy-MM-dd HH:mm:ss</maven.build.timestamp.format>
<version.template.file>version.txt.template</version.template.file>
Expand Down Expand Up @@ -43,7 +43,7 @@
</snapshotRepository>
</distributionManagement>
<dependencies>
<!-- <dependency> <groupId>com.google.guava</groupId> <artifactId>guava-parent</artifactId>
<!-- <dependency> <groupId>com.google.guava</groupId> <artifactId>guava-parent</artifactId>
<version>18.0</version> </dependency> -->
<dependency>
<groupId>org.mongodb</groupId>
Expand Down Expand Up @@ -298,7 +298,7 @@
<goals>
<goal>test-jar</goal>
</goals>
<!-- configuration> <finalName>${project.build.finalName}-${buildNumber}</finalName>
<!-- configuration> <finalName>${project.build.finalName}-${buildNumber}</finalName>
</configuration -->
</execution>
</executions>
Expand All @@ -315,7 +315,7 @@
<additionalConfig>
<file>
<name>.settings/org.eclipse.core.resources.prefs</name>
<content>
<content>
<![CDATA[eclipse.preferences.version=1${line.separator}encoding/<project>=${app.encoding}${line.separator}]]>
</content>
</file>
Expand Down
3 changes: 3 additions & 0 deletions src/main/conf/dnindex.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#update
#Thu Sep 10 16:14:18 CST 2015
jdbchost=0
8 changes: 4 additions & 4 deletions src/main/java/demo/catlets/BatchInsertSequence.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package demo.catlets;

import io.mycat.MycatServer;
import io.mycat.cache.LayerCachePool;
import io.mycat.route.RouteResultset;
import io.mycat.route.RouteResultsetNode;
import io.mycat.route.factory.RouteStrategyFactory;
import io.mycat.server.ErrorCode;
import io.mycat.server.MySQLFrontConnection;
import io.mycat.server.MycatServer;
import io.mycat.server.SystemConfig;
import io.mycat.server.config.SchemaConfig;
import io.mycat.server.config.TableConfig;
import io.mycat.server.config.node.SchemaConfig;
import io.mycat.server.config.node.SystemConfig;
import io.mycat.server.config.node.TableConfig;
import io.mycat.server.parser.ServerParse;
import io.mycat.server.sequence.IncrSequenceMySQLHandler;
import io.mycat.server.sequence.IncrSequencePropHandler;
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/demo/catlets/MyHellowJoin.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import io.mycat.cache.LayerCachePool;
import io.mycat.server.MySQLFrontConnection;
import io.mycat.server.SystemConfig;
import io.mycat.server.config.SchemaConfig;
import io.mycat.server.config.node.SchemaConfig;
import io.mycat.server.config.node.SystemConfig;
import io.mycat.server.packet.RowDataPacket;
import io.mycat.sqlengine.AllJobFinishedListener;
import io.mycat.sqlengine.Catlet;
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/demo/catlets/ShareJoin.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
import io.mycat.route.factory.RouteStrategyFactory;
import io.mycat.server.ErrorCode;
import io.mycat.server.MySQLFrontConnection;
import io.mycat.server.SystemConfig;
import io.mycat.server.config.SchemaConfig;
import io.mycat.server.config.node.SchemaConfig;
import io.mycat.server.config.node.SystemConfig;
import io.mycat.server.packet.FieldPacket;
import io.mycat.server.packet.RowDataPacket;
import io.mycat.server.parser.ServerParse;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
* Copyright (c) 2013, OpenCloudDB/MyCAT and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software;Designed and Developed mainly by many Chinese
* opensource volunteers. you can redistribute it and/or modify it under the
* This code is free software;Designed and Developed mainly by many Chinese
* opensource volunteers. you can redistribute it and/or modify it under the
* terms of the GNU General Public License version 2 only, as published by the
* Free Software Foundation.
*
Expand All @@ -16,15 +16,13 @@
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Any questions about this component can be directed to it's project Web address
*
* Any questions about this component can be directed to it's project Web address
* https://code.google.com/p/opencloudb/.
*
*/
package io.mycat.server;
package io.mycat;

import io.mycat.Log4jInitializer;
import io.mycat.MycatConfig;
import io.mycat.backend.PhysicalDBPool;
import io.mycat.cache.CacheService;
import io.mycat.net.BufferPool;
Expand All @@ -37,17 +35,22 @@
import io.mycat.net.NetSystem;
import io.mycat.route.MyCATSequnceProcessor;
import io.mycat.route.RouteService;
import io.mycat.server.MySQLFrontConnectionFactory;
import io.mycat.server.MySQLFrontConnectionHandler;
import io.mycat.server.classloader.DynaClassLoader;
import io.mycat.server.config.ConfigException;
import io.mycat.server.config.Log4jInitializer;
import io.mycat.server.config.cluster.ClusterSync;
import io.mycat.server.config.loader.ConfigFactory;
import io.mycat.server.config.node.MycatConfig;
import io.mycat.server.config.node.SystemConfig;
import io.mycat.server.interceptor.SQLInterceptor;
import io.mycat.util.TimeUtil;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.channels.AsynchronousChannelGroup;
import java.util.Map;
import java.util.Properties;
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.atomic.AtomicBoolean;
Expand All @@ -69,7 +72,6 @@ public class MycatServer {
private static final Logger LOGGER = Logger.getLogger("MycatServer");
private final RouteService routerService;
private final CacheService cacheService;
private Properties dnIndexProperties;
private AsynchronousChannelGroup[] asyncChannelGroups;
private volatile int channelIndex = 0;
private final MyCATSequnceProcessor sequnceProcessor = new MyCATSequnceProcessor();
Expand All @@ -88,14 +90,14 @@ public static final MycatServer getInstance() {
private NamebleScheduledExecutor timerExecutor;
private ListeningExecutorService listeningExecutorService;

private ClusterSync clusterSync;

public MycatServer() {
this.config = new MycatConfig();
this.timer = new Timer(NAME + "Timer", true);
this.isOnline = new AtomicBoolean(true);
cacheService = new CacheService();
routerService = new RouteService(cacheService);
// load datanode active index from properties
dnIndexProperties = loadDnIndexProps();
try {
sqlInterceptor = (SQLInterceptor) Class.forName(
config.getSystem().getSqlInterceptor()).newInstance();
Expand All @@ -105,6 +107,8 @@ public MycatServer() {
catletClassLoader = new DynaClassLoader(SystemConfig.getHomePath()
+ File.separator + "catlet", config.getSystem()
.getCatletClassCheckSeconds());


this.startupTime = TimeUtil.currentTimeMillis();
}

Expand Down Expand Up @@ -137,7 +141,7 @@ public String genXATXID() {
/**
* get next AsynchronousChannel ,first is exclude if multi
* AsynchronousChannelGroups
*
*
* @return
*/
public AsynchronousChannelGroup getNextAsyncChannelGroup() {
Expand Down Expand Up @@ -230,18 +234,8 @@ public void startup() throws IOException {
+ server.getPort());
LOGGER.info("===============================================");
// init datahost
Map<String, PhysicalDBPool> dataHosts = config.getDataHosts();
LOGGER.info("Initialize dataHost ...");
for (PhysicalDBPool node : dataHosts.values()) {
String index = dnIndexProperties.getProperty(node.getHostName(),
"0");
if (!"0".equals(index)) {
LOGGER.info("init datahost: " + node.getHostName()
+ " to use datasource index:" + index);
}
node.init(Integer.valueOf(index));
node.startHeartbeat();
}
config.initDatasource();

long dataNodeIldeCheckPeriod = system.getDataNodeIdleCheckPeriod();
timer.schedule(updateTime(), 0L, TIME_UPDATE_PERIOD);
timer.schedule(processorCheck(), 0L, system.getProcessorCheckPeriod());
Expand All @@ -266,70 +260,7 @@ public void run() {
};
}

private Properties loadDnIndexProps() {
Properties prop = new Properties();
File file = new File(SystemConfig.getHomePath(), "conf"
+ File.separator + "dnindex.properties");
if (!file.exists()) {
return prop;
}
FileInputStream filein = null;
try {
filein = new FileInputStream(file);
prop.load(filein);
} catch (Exception e) {
LOGGER.warn("load DataNodeIndex err:" + e);
} finally {
if (filein != null) {
try {
filein.close();
} catch (IOException e) {
}
}
}
return prop;
}

/**
* save cur datanode index to properties file
*
* @param dataNode
* @param curIndex
*/
public synchronized void saveDataHostIndex(String dataHost, int curIndex) {

File file = new File(SystemConfig.getHomePath(), "conf"
+ File.separator + "dnindex.properties");
FileOutputStream fileOut = null;
try {
String oldIndex = dnIndexProperties.getProperty(dataHost);
String newIndex = String.valueOf(curIndex);
if (newIndex.equals(oldIndex)) {
return;
}
dnIndexProperties.setProperty(dataHost, newIndex);
LOGGER.info("save DataHost index " + dataHost + " cur index "
+ curIndex);

File parent = file.getParentFile();
if (parent != null && !parent.exists()) {
parent.mkdirs();
}

fileOut = new FileOutputStream(file);
dnIndexProperties.store(fileOut, "update");
} catch (Exception e) {
LOGGER.warn("saveDataNodeIndex err:", e);
} finally {
if (fileOut != null) {
try {
fileOut.close();
} catch (IOException e) {
}
}
}

}

public RouteService getRouterService() {
return routerService;
Expand Down Expand Up @@ -437,4 +368,22 @@ public void run() {
public ListeningExecutorService getListeningExecutorService() {
return listeningExecutorService;
}
/**
* save cur datanode index to properties file
*
* @param dataNode
* @param curIndex
*/
public synchronized void saveDataHostIndex(String dataHost, int curIndex) {
if(clusterSync==null){
clusterSync = ConfigFactory.instanceCluster();
}
boolean isSwitch = clusterSync.switchDataSource(dataHost, curIndex);
if(isSwitch){
config.setHostIndex(dataHost, curIndex);
}else {
LOGGER.warn("can't switch dataHost"+dataHost +" to curIndex " + curIndex);
throw new ConfigException("can't switch dataHost"+dataHost +" to curIndex " + curIndex);
}
}
}
3 changes: 1 addition & 2 deletions src/main/java/io/mycat/MycatStartup.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@
*/
package io.mycat;

import io.mycat.server.MycatServer;
import io.mycat.server.SystemConfig;
import io.mycat.server.config.node.SystemConfig;

import java.text.SimpleDateFormat;
import java.util.Date;
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/io/mycat/backend/MySQLDataSource.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
import io.mycat.backend.heartbeat.DBHeartbeat;
import io.mycat.backend.heartbeat.MySQLHeartbeat;
import io.mycat.backend.nio.MySQLBackendConnectionFactory;
import io.mycat.server.config.DBHostConfig;
import io.mycat.server.config.DataHostConfig;
import io.mycat.server.config.node.DBHostConfig;
import io.mycat.server.config.node.DataHostConfig;
import io.mycat.server.executors.ResponseHandler;

import java.io.IOException;
Expand Down
11 changes: 5 additions & 6 deletions src/main/java/io/mycat/backend/PhysicalDBPool.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
*/
package io.mycat.backend;

import io.mycat.MycatServer;
import io.mycat.backend.heartbeat.DBHeartbeat;
import io.mycat.server.Alarms;
import io.mycat.server.MycatServer;
import io.mycat.server.config.DataHostConfig;
import io.mycat.server.config.node.DataHostConfig;
import io.mycat.server.executors.GetConnectionHandler;
import io.mycat.server.executors.ResponseHandler;

Expand Down Expand Up @@ -249,8 +249,7 @@ public void init(int index) {

if (this.writeType == WRITE_ONLYONE_NODE) {
// only init one write datasource
MycatServer.getInstance().saveDataHostIndex(hostName,
activedIndex);
MycatServer.getInstance().saveDataHostIndex(hostName, activedIndex);
break;
}
}
Expand Down Expand Up @@ -473,15 +472,15 @@ private boolean canSelectAsReadNode(PhysicalDatasource theSource) {

/**
* return all backup write sources
*
*
* @param includeWriteNode if include write nodes
* @param includeCurWriteNode if include current active write node. invalid when <code>includeWriteNode<code> is false
* @param filterWithSlaveThreshold
*
* @return
*/
private ArrayList<PhysicalDatasource> getAllActiveRWSources(
boolean includeWriteNode,
boolean includeWriteNode,
boolean includeCurWriteNode, boolean filterWithSlaveThreshold) {
int curActive = activedIndex;
ArrayList<PhysicalDatasource> okSources = new ArrayList<PhysicalDatasource>(
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/io/mycat/backend/PhysicalDatasource.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
import io.mycat.backend.heartbeat.DBHeartbeat;
import io.mycat.net.NetSystem;
import io.mycat.server.Alarms;
import io.mycat.server.config.DBHostConfig;
import io.mycat.server.config.DataHostConfig;
import io.mycat.server.config.node.DBHostConfig;
import io.mycat.server.config.node.DataHostConfig;
import io.mycat.server.executors.ConnectionHeartBeatHandler;
import io.mycat.server.executors.DelegateResponseHandler;
import io.mycat.server.executors.NewConnectionRespHandler;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import io.mycat.backend.MySQLDataSource;
import io.mycat.backend.PhysicalDBPool;
import io.mycat.backend.PhysicalDatasource;
import io.mycat.server.config.DataHostConfig;
import io.mycat.server.config.node.DataHostConfig;
import io.mycat.sqlengine.OneRawSQLQueryResultHandler;
import io.mycat.sqlengine.SQLJob;
import io.mycat.sqlengine.SQLQueryResult;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import io.mycat.backend.MySQLDataSource;
import io.mycat.backend.PhysicalDBPool;
import io.mycat.backend.PhysicalDatasource;
import io.mycat.server.config.DataHostConfig;
import io.mycat.server.config.node.DataHostConfig;

import java.text.SimpleDateFormat;
import java.util.Date;
Expand Down
Loading

0 comments on commit 04e2bde

Please sign in to comment.