use of com.actiontech.dble.config.model.SchemaConfig in project dble by actiontech.
the class NoNameNodeHandlerBuilder method buildOwn.
@Override
public void buildOwn() {
PushDownVisitor visitor = new PushDownVisitor(node, true);
visitor.visit();
this.canPushDown = true;
String sql = visitor.getSql().toString();
String schema = session.getSource().getSchema();
SchemaConfig schemaConfig = schemaConfigMap.get(schema);
RouteResultsetNode[] rrss = getTableSources(schemaConfig.getAllDataNodes(), sql);
hBuilder.checkRRSs(rrss);
MultiNodeMergeHandler mh = new MultiNodeMergeHandler(getSequenceId(), rrss, session.getSource().isAutocommit() && !session.getSource().isTxStart(), session, null);
addHandler(mh);
}
use of com.actiontech.dble.config.model.SchemaConfig in project dble by actiontech.
the class CKVStoreRepository method init.
@Override
public void init() {
List<UKvBean> allList = ClusterUcoreSender.getKeyTree(UcorePathUtil.getViewPath());
for (UKvBean bean : allList) {
String[] key = bean.getKey().split("/");
if (key.length == 5) {
String[] value = key[key.length - 1].split(SCHEMA_VIEW_SPLIT);
if (viewCreateSqlMap.get(value[0]) == null) {
Map<String, String> schemaMap = new ConcurrentHashMap<String, String>();
viewCreateSqlMap.put(value[0], schemaMap);
}
viewCreateSqlMap.get(value[0]).put(value[1], bean.getValue());
}
}
for (Map.Entry<String, SchemaConfig> schema : DbleServer.getInstance().getConfig().getSchemas().entrySet()) {
if (viewCreateSqlMap.get(schema.getKey()) == null) {
viewCreateSqlMap.put(schema.getKey(), new ConcurrentHashMap<String, String>());
}
}
}
use of com.actiontech.dble.config.model.SchemaConfig in project dble by actiontech.
the class ReloadConfig method reload.
public static void reload() throws Exception {
/* 1 load new conf, ConfigInitializer will check itself */
ConfigInitializer loader;
try {
loader = new ConfigInitializer(false, DbleServer.getInstance().getSystemVariables().isLowerCaseTableNames());
} catch (Exception e) {
throw new Exception(e);
}
Map<String, UserConfig> users = loader.getUsers();
Map<String, SchemaConfig> schemas = loader.getSchemas();
Map<String, PhysicalDBNode> dataNodes = loader.getDataNodes();
Map<String, PhysicalDBPool> dataHosts = loader.getDataHosts();
Map<ERTable, Set<ERTable>> erRelations = loader.getErRelations();
FirewallConfig firewall = loader.getFirewall();
/* 2 apply the new conf */
DbleServer.getInstance().getConfig().reload(users, schemas, dataNodes, dataHosts, erRelations, firewall, DbleServer.getInstance().getSystemVariables(), loader.isDataHostWithoutWH(), false);
}
use of com.actiontech.dble.config.model.SchemaConfig in project dble by actiontech.
the class ReloadConfig method reloadAll.
public static void reloadAll(final int loadAllMode) throws Exception {
/*
* 1 load new conf
* 1.1 ConfigInitializer init adn check itself
* 1.2 DataNode/DataHost test connection
*/
ConfigInitializer loader;
try {
loader = new ConfigInitializer(true, DbleServer.getInstance().getSystemVariables().isLowerCaseTableNames());
} catch (Exception e) {
throw new Exception(e);
}
Map<String, UserConfig> newUsers = loader.getUsers();
Map<String, SchemaConfig> newSchemas = loader.getSchemas();
Map<String, PhysicalDBNode> newDataNodes = loader.getDataNodes();
Map<String, PhysicalDBPool> newDataHosts = loader.getDataHosts();
Map<ERTable, Set<ERTable>> newErRelations = loader.getErRelations();
FirewallConfig newFirewall = loader.getFirewall();
SystemVariables newSystemVariables = DbleServer.getInstance().getSystemVariables();
if (!loader.isDataHostWithoutWH()) {
VarsExtractorHandler handler = new VarsExtractorHandler(newDataNodes);
newSystemVariables = handler.execute();
ConfigInitializer confInit = new ConfigInitializer(newSystemVariables.isLowerCaseTableNames());
newUsers = confInit.getUsers();
newSchemas = confInit.getSchemas();
newDataNodes = confInit.getDataNodes();
newErRelations = confInit.getErRelations();
newFirewall = confInit.getFirewall();
newDataHosts = confInit.getDataHosts();
}
if ((loadAllMode & ManagerParseConfig.OPTT_MODE) != 0) {
try {
loader.testConnection(false);
} catch (Exception e) {
throw new Exception(e);
}
}
/*
* 2 transform
* 2.1 old dataSource continue to work
* 2.2 init the new dataSource
* 2.3 transform
* 2.4 put the old connection into a queue
*/
ServerConfig config = DbleServer.getInstance().getConfig();
/* 2.1 do nothing */
boolean isReloadStatusOK = true;
/* 2.2 init the new dataSource */
for (PhysicalDBPool dbPool : newDataHosts.values()) {
String hostName = dbPool.getHostName();
// set schemas
ArrayList<String> dnSchemas = new ArrayList<>(30);
for (PhysicalDBNode dn : newDataNodes.values()) {
if (dn.getDbPool().getHostName().equals(hostName)) {
dnSchemas.add(dn.getDatabase());
}
}
dbPool.setSchemas(dnSchemas.toArray(new String[dnSchemas.size()]));
// get data host
String dnIndex = DnPropertyUtil.loadDnIndexProps().getProperty(dbPool.getHostName(), "0");
if (!"0".equals(dnIndex)) {
LOGGER.info("init data host: " + dbPool.getHostName() + " to use datasource index:" + dnIndex);
}
dbPool.init(Integer.parseInt(dnIndex));
if (!dbPool.isInitSuccess()) {
isReloadStatusOK = false;
break;
}
}
if (isReloadStatusOK) {
/* 2.3 apply new conf */
config.reload(newUsers, newSchemas, newDataNodes, newDataHosts, newErRelations, newFirewall, newSystemVariables, loader.isDataHostWithoutWH(), true);
recycleOldBackendConnections(config, ((loadAllMode & ManagerParseConfig.OPTF_MODE) != 0));
AlarmAppender.refreshConfig();
} else {
// INIT FAILED
LOGGER.info("reload failed, clear previously created data sources ");
for (PhysicalDBPool dbPool : newDataHosts.values()) {
dbPool.clearDataSources("reload config");
dbPool.stopHeartbeat();
}
throw new Exception("Init DbPool failed");
}
}
use of com.actiontech.dble.config.model.SchemaConfig in project dble by actiontech.
the class ShowDataNode method execute.
public static void execute(ManagerConnection c, String name) {
ByteBuffer buffer = c.allocate();
// write header
buffer = HEADER.write(buffer, c, true);
// write fields
for (FieldPacket field : FIELDS) {
buffer = field.write(buffer, c, true);
}
// write eof
buffer = EOF.write(buffer, c, true);
// write rows
byte packetId = EOF.getPacketId();
ServerConfig conf = DbleServer.getInstance().getConfig();
Map<String, PhysicalDBNode> dataNodes = conf.getDataNodes();
List<String> keys = new ArrayList<>();
if (StringUtil.isEmpty(name)) {
keys.addAll(dataNodes.keySet());
} else {
SchemaConfig sc = conf.getSchemas().get(name);
if (null != sc) {
keys.addAll(sc.getAllDataNodes());
}
}
Collections.sort(keys, new Comparator<String>() {
@Override
public int compare(String o1, String o2) {
Pair<String, Integer> p1 = PairUtil.splitIndex(o1, '[', ']');
Pair<String, Integer> p2 = PairUtil.splitIndex(o2, '[', ']');
if (p1.getKey().compareTo(p2.getKey()) == 0) {
return p1.getValue() - p2.getValue();
} else {
return p1.getKey().compareTo(p2.getKey());
}
}
});
for (String key : keys) {
RowDataPacket row = getRow(dataNodes.get(key), c.getCharset().getResults());
if (row != null) {
row.setPacketId(++packetId);
buffer = row.write(buffer, c, true);
}
}
// write last eof
EOFPacket lastEof = new EOFPacket();
lastEof.setPacketId(++packetId);
buffer = lastEof.write(buffer, c, true);
// post write
c.write(buffer);
}
Aggregations