use of io.mycat.plug.sequence.SequenceGenerator in project Mycat2 by MyCATApache.
the class MycatRouterConfigOps method commit.
@Override
public void commit() throws Exception {
ServerConfig serverConfig = MetaClusterCurrent.wrapper(ServerConfig.class);
boolean init = isInit();
MycatRouterConfig newConfig = this.newConfig;
if (!init && Objects.equals(this.original, newConfig)) {
LOGGER.info("=======================================config no changed===========================================");
return;
}
if (LOGGER.isDebugEnabled()) {
LOGGER.debug(JsonUtil.toJson(this.original));
LOGGER.debug("===========================================change to ===========================================");
LOGGER.debug(JsonUtil.toJson(newConfig));
}
UpdateSet<LogicSchemaConfig> schemaConfigUpdateSet = UpdateSet.create(newConfig.getSchemas(), original.getSchemas());
UpdateSet<ClusterConfig> clusterConfigUpdateSet = UpdateSet.create(newConfig.getClusters(), original.getClusters());
UpdateSet<DatasourceConfig> datasourceConfigUpdateSet = UpdateSet.create(newConfig.getDatasources(), original.getDatasources());
UpdateSet<SequenceConfig> sequenceConfigUpdateSet = UpdateSet.create(newConfig.getSequences(), original.getSequences());
UpdateSet<SqlCacheConfig> sqlCacheConfigUpdateSet = UpdateSet.create(newConfig.getSqlCacheConfigs(), original.getSqlCacheConfigs());
UpdateSet<UserConfig> userConfigUpdateSet = UpdateSet.create(newConfig.getUsers(), original.getUsers());
List<Resource> resourceList = new ArrayList<>();
boolean connectionUpdateSuccess = false;
boolean allSuccess = false;
try {
// //////////////////////////////////////////////////////////////////////////////////////////////////////////
if (MetaClusterCurrent.exist(ReplicaSelectorManager.class)) {
ReplicaSelectorManager replicaSelectorManager = MetaClusterCurrent.wrapper(ReplicaSelectorManager.class);
replicaSelectorManager.stop();
}
// //////////////////////////////////////////////////////////////////////////////////////////////////////////
Resource<JdbcConnectionManager> jdbcConnectionManager = getJdbcConnectionManager(datasourceConfigUpdateSet);
resourceList.add(jdbcConnectionManager);
Resource<DatasourceConfigProvider> datasourceConfigProvider = getDatasourceConfigProvider(datasourceConfigUpdateSet);
resourceList.add(datasourceConfigProvider);
Resource<MySQLManager> mycatMySQLManager = getMycatMySQLManager(datasourceConfigUpdateSet);
resourceList.add(mycatMySQLManager);
Resource<ReplicaSelectorManager> replicaSelectorManager = getReplicaSelectorManager(clusterConfigUpdateSet, datasourceConfigUpdateSet, jdbcConnectionManager);
resourceList.add(replicaSelectorManager);
JdbcConnectionManager jdbcConnectionManager1 = jdbcConnectionManager.get();
MetaClusterCurrent.register(JdbcConnectionManager.class, jdbcConnectionManager.get());
MetaClusterCurrent.register(ConnectionManager.class, jdbcConnectionManager.get());
resourceList.add(jdbcConnectionManager);
MetaClusterCurrent.register(DatasourceConfigProvider.class, datasourceConfigProvider.get());
MetaClusterCurrent.register(ReplicaSelectorManager.class, replicaSelectorManager.get());
MetaClusterCurrent.register(MySQLManager.class, mycatMySQLManager.get());
// testPrototype(jdbcConnectionManager1);
// ////////////////////////////////////////////////////////////////////////////////////////////////////////
resourceList.clear();
connectionUpdateSuccess = true;
// ////////////////////////////////////////////////////////////////////////////////////////////////////////
Map<Class, Object> context = MetaClusterCurrent.copyContext();
Resource<Authenticator> authenticator = getAuthenticator(userConfigUpdateSet);
resourceList.add(authenticator);
Resource<SqlResultSetService> sqlResultSetService = getSqlResultSetService(sqlCacheConfigUpdateSet);
resourceList.add(sqlResultSetService);
Resource<SequenceGenerator> sequenceGenerator = getSequenceGenerator(sequenceConfigUpdateSet);
resourceList.add(sequenceGenerator);
PrototypeService prototypeService;
context.put(PrototypeService.class, prototypeService = new PrototypeService());
Resource<MetadataManager> metadataManager = getMetadataManager(schemaConfigUpdateSet, prototypeService);
resourceList.add(metadataManager);
Resource<DrdsSqlCompiler> drdsSqlCompiler = getDrdsSqlCompiler(schemaConfigUpdateSet, metadataManager);
resourceList.add(drdsSqlCompiler);
StatisticCenter statisticCenter = new StatisticCenter();
Resource<MysqlVariableService> mysqlVariableService = getMysqlVariableService(jdbcConnectionManager);
resourceList.add(mysqlVariableService);
Resource<QueryPlanner> queryPlanner = getQueryPlanner(schemaConfigUpdateSet);
resourceList.add(queryPlanner);
Resource<XaLog> xaLog = getXaLog(serverConfig, mycatMySQLManager);
resourceList.add(xaLog);
Resource<UpdatePlanCache> updatePlanCache = getUpdatePlanCache(schemaConfigUpdateSet);
resourceList.add(updatePlanCache);
context.put(JdbcConnectionManager.class, jdbcConnectionManager.get());
context.put(ConnectionManager.class, jdbcConnectionManager.get());
context.put(Authenticator.class, authenticator.get());
context.put(SqlResultSetService.class, sqlResultSetService.get());
context.put(SequenceGenerator.class, sequenceGenerator.get());
context.put(DatasourceConfigProvider.class, datasourceConfigProvider.get());
context.put(ReplicaSelectorManager.class, replicaSelectorManager.get());
context.put(MySQLManager.class, mycatMySQLManager.get());
context.put(DrdsSqlCompiler.class, drdsSqlCompiler.get());
context.put(MysqlVariableService.class, mysqlVariableService.get());
context.put(XaLog.class, xaLog.get());
context.put(UpdatePlanCache.class, updatePlanCache.get());
context.put(QueryPlanner.class, queryPlanner.get());
context.put(StatisticCenter.class, statisticCenter);
context.put(MycatRouterConfig.class, newConfig);
context.put(MetadataManager.class, metadataManager.get());
MetaClusterCurrent.register(context);
allSuccess = true;
if (init) {
recoveryXA();
DbPlanManagerPersistorImpl dbPlanManagerPersistor = new DbPlanManagerPersistorImpl();
dbPlanManagerPersistor.checkStore();
}
QueryPlanner planner = MetaClusterCurrent.wrapper(QueryPlanner.class);
// planner.innerComputeMinCostCodeExecuterContext( DrdsRunnerHelper.preParse("select 1",null));
// planner.innerComputeMinCostCodeExecuterContext(DrdsRunnerHelper.preParse("select 'x'",null));
// hotswap
// //////////////////////////////////////////////////////////////////////////////////////////////////////////
} finally {
if (!allSuccess) {
resourceList.forEach(c -> c.giveup());
}
if (MetaClusterCurrent.exist(ReplicaSelectorManager.class)) {
ReplicaSelectorManager replicaSelectorManager = MetaClusterCurrent.wrapper(ReplicaSelectorManager.class);
replicaSelectorManager.start();
}
}
if (options.createSchemaName != null) {
MetadataManager metadataManager = MetaClusterCurrent.wrapper(MetadataManager.class);
TableHandler table = metadataManager.getTable(options.createSchemaName, options.createTableName);
if (table != null) {
table.createPhysicalTables();
}
}
if (options.persistence) {
persistence(schemaConfigUpdateSet, clusterConfigUpdateSet, datasourceConfigUpdateSet, sequenceConfigUpdateSet, sqlCacheConfigUpdateSet, userConfigUpdateSet);
}
}
use of io.mycat.plug.sequence.SequenceGenerator in project Mycat2 by MyCATApache.
the class MycatRouterConfigOps method getSequenceGenerator.
@NotNull
private Resource<SequenceGenerator> getSequenceGenerator(UpdateSet<SequenceConfig> sequenceConfigUpdateSet) {
if (sequenceConfigUpdateSet.isEmpty() && MetaClusterCurrent.exist(SequenceGenerator.class)) {
return Resource.of(MetaClusterCurrent.wrapper(SequenceGenerator.class), true);
}
Collection<SequenceConfig> target = sequenceConfigUpdateSet.getTarget();
ServerConfig serverConfig = MetaClusterCurrent.wrapper(ServerConfig.class);
SequenceGenerator sequenceGenerator = new SequenceGenerator(serverConfig.getMycatId(), target);
return Resource.of(sequenceGenerator, false);
}
Aggregations