mirror of
https://github.com/actiontech/dble.git
synced 2026-01-24 13:58:29 -06:00
reload meta data
This commit is contained in:
@@ -50,6 +50,7 @@ import org.slf4j.LoggerFactory;
|
||||
import com.google.common.io.Files;
|
||||
import com.google.common.util.concurrent.ListeningExecutorService;
|
||||
import com.google.common.util.concurrent.MoreExecutors;
|
||||
import com.google.common.util.concurrent.ThreadFactoryBuilder;
|
||||
|
||||
import io.mycat.backend.BackendConnection;
|
||||
import io.mycat.backend.datasource.PhysicalDBNode;
|
||||
@@ -166,7 +167,7 @@ public class MycatServer {
|
||||
this.config = new MycatConfig();
|
||||
|
||||
//定时线程池,单线程线程池
|
||||
scheduler = Executors.newSingleThreadScheduledExecutor();
|
||||
scheduler = Executors.newSingleThreadScheduledExecutor(new ThreadFactoryBuilder().setNameFormat("TimerScheduler-%d").build());
|
||||
|
||||
/**
|
||||
* 是否在线,MyCat manager中有命令控制
|
||||
@@ -442,9 +443,6 @@ public class MycatServer {
|
||||
scheduler.schedule(catletClassClear(), 30000,TimeUnit.MILLISECONDS);
|
||||
scheduler.scheduleWithFixedDelay(xaSessionCheck(), 0L, system.getxaSessionCheckPeriod(),TimeUnit.MILLISECONDS);
|
||||
scheduler.scheduleWithFixedDelay(xaLogClean(), 0L, system.getxaLogCleanPeriod(),TimeUnit.MILLISECONDS);
|
||||
if (system.getCheckTableConsistency() == 1) {
|
||||
scheduler.scheduleWithFixedDelay(tableStructureCheck(), 0L, system.getCheckTableConsistencyPeriod(), TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
||||
if (system.getUseSqlStat() == 1) {
|
||||
scheduler.scheduleWithFixedDelay(recycleSqlStat(), 0L, DEFAULT_SQL_STAT_RECYCLE_PERIOD, TimeUnit.MILLISECONDS);
|
||||
@@ -483,6 +481,11 @@ public class MycatServer {
|
||||
}
|
||||
}
|
||||
|
||||
public void reloadMetaData(){
|
||||
tmManager.terminate();
|
||||
tmManager = new ProxyMetaManager();
|
||||
tmManager.init();
|
||||
}
|
||||
|
||||
public void reloadDnIndex()
|
||||
{
|
||||
@@ -863,21 +866,6 @@ public class MycatServer {
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
//定时检查不同分片表结构一致性
|
||||
private Runnable tableStructureCheck(){
|
||||
return new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
timerExecutor.execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
tmManager.tableStructureCheck();
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// 全局表一致性检查任务
|
||||
private Runnable glableTableConsistencyCheck() {
|
||||
|
||||
@@ -203,6 +203,7 @@ public final class ReloadConfig {
|
||||
|
||||
//清理缓存
|
||||
MycatServer.getInstance().getCacheService().clearCache();
|
||||
MycatServer.getInstance().reloadMetaData();
|
||||
return true;
|
||||
|
||||
} else {
|
||||
@@ -239,6 +240,7 @@ public final class ReloadConfig {
|
||||
* 3、清理缓存
|
||||
*/
|
||||
MycatServer.getInstance().getCacheService().clearCache();
|
||||
MycatServer.getInstance().reloadMetaData();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -117,6 +117,7 @@ public final class RollbackConfig {
|
||||
|
||||
//清理缓存
|
||||
MycatServer.getInstance().getCacheService().clearCache();
|
||||
MycatServer.getInstance().reloadMetaData();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,10 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.locks.Condition;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
@@ -41,9 +45,12 @@ import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlAlterTableModifyCo
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlCreateTableStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser;
|
||||
import com.alibaba.druid.sql.parser.SQLStatementParser;
|
||||
import com.google.common.util.concurrent.ThreadFactoryBuilder;
|
||||
|
||||
import io.mycat.MycatServer;
|
||||
import io.mycat.config.MycatConfig;
|
||||
import io.mycat.config.model.SchemaConfig;
|
||||
import io.mycat.config.model.SystemConfig;
|
||||
import io.mycat.config.model.TableConfig;
|
||||
import io.mycat.meta.protocol.MyCatMeta.ColumnMeta;
|
||||
import io.mycat.meta.protocol.MyCatMeta.IndexMeta;
|
||||
@@ -64,6 +71,8 @@ public class ProxyMetaManager {
|
||||
private final Set<String> lockTables;
|
||||
private ReentrantLock metalock = new ReentrantLock();
|
||||
private Condition condRelease = metalock.newCondition();
|
||||
private ScheduledExecutorService scheduler;
|
||||
private ScheduledFuture<?> checkTaskHandler;
|
||||
public ProxyMetaManager() {
|
||||
this.catalogs = new ConcurrentHashMap<String, SchemaMeta>();
|
||||
this.lockTables= new HashSet<String>();
|
||||
@@ -370,11 +379,32 @@ public class ProxyMetaManager {
|
||||
// }
|
||||
|
||||
public void init() {
|
||||
SchemaMetaHandler handler = new SchemaMetaHandler(MycatServer.getInstance().getConfig());
|
||||
MycatConfig config = MycatServer.getInstance().getConfig();
|
||||
SchemaMetaHandler handler = new SchemaMetaHandler(config);
|
||||
handler.execute();
|
||||
SystemConfig system = config.getSystem();
|
||||
if (system.getCheckTableConsistency() == 1) {
|
||||
scheduler= Executors.newSingleThreadScheduledExecutor(new ThreadFactoryBuilder().setNameFormat("MetaDataChecker-%d").build());
|
||||
checkTaskHandler = scheduler.scheduleWithFixedDelay(tableStructureCheckTask(), 0L, system.getCheckTableConsistencyPeriod(), TimeUnit.MILLISECONDS);
|
||||
}
|
||||
}
|
||||
|
||||
public void tableStructureCheck() {
|
||||
public void terminate(){
|
||||
if (checkTaskHandler != null) {
|
||||
checkTaskHandler.cancel(false);
|
||||
scheduler.shutdown();
|
||||
}
|
||||
catalogs.clear();
|
||||
}
|
||||
//定时检查不同分片表结构一致性
|
||||
private Runnable tableStructureCheckTask() {
|
||||
return new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
tableStructureCheck();
|
||||
}
|
||||
};
|
||||
}
|
||||
private void tableStructureCheck() {
|
||||
for (SchemaConfig schema : MycatServer.getInstance().getConfig().getSchemas().values()) {
|
||||
if (!checkDbExists(schema.getName())) {
|
||||
continue;
|
||||
|
||||
Reference in New Issue
Block a user