use of com.actiontech.dble.server.util.SchemaUtil.SchemaInfo in project dble by actiontech.
the class ProxyMetaManager method createIndex.
private void createIndex(String schema, String sql, SQLCreateIndexStatement statement, boolean isSuccess, boolean needNotifyOther) {
SQLTableSource tableSource = statement.getTable();
if (tableSource instanceof SQLExprTableSource) {
SQLExprTableSource exprTableSource = (SQLExprTableSource) tableSource;
SchemaInfo schemaInfo = getSchemaInfo(schema, exprTableSource);
try {
if (!isSuccess) {
return;
}
StructureMeta.TableMeta orgTbMeta = getTableMeta(schemaInfo.getSchema(), schemaInfo.getTable());
if (orgTbMeta == null)
return;
String indexName = StringUtil.removeBackQuote(statement.getName().getSimpleName());
StructureMeta.TableMeta.Builder tmBuilder = orgTbMeta.toBuilder();
if (statement.getType() == null) {
addIndex(indexName, tmBuilder, IndexType.MUL, itemsToColumns(statement.getItems()));
} else if (statement.getType().equals("UNIQUE")) {
addIndex(indexName, tmBuilder, IndexType.UNI, itemsToColumns(statement.getItems()));
}
} catch (Exception e) {
LOGGER.info("updateMetaData failed,sql is" + statement.toString(), e);
} finally {
try {
notifyResponseClusterDDL(schemaInfo.getSchema(), schemaInfo.getTable(), sql, isSuccess ? DDLInfo.DDLStatus.SUCCESS : DDLInfo.DDLStatus.FAILED, needNotifyOther);
} catch (Exception e) {
LOGGER.warn(AlarmCode.CORE_CLUSTER_WARN + "notifyResponseZKDdl error", e);
}
removeMetaLock(schemaInfo.getSchema(), schemaInfo.getTable());
}
}
}
use of com.actiontech.dble.server.util.SchemaUtil.SchemaInfo in project dble by actiontech.
the class ProxyMetaManager method truncateTable.
private void truncateTable(String schema, String sql, SQLTruncateStatement statement, boolean isSuccess, boolean needNotifyOther) {
// TODO:reset Sequence?
SQLExprTableSource exprTableSource = statement.getTableSources().get(0);
SchemaInfo schemaInfo = getSchemaInfo(schema, exprTableSource);
try {
notifyResponseClusterDDL(schemaInfo.getSchema(), schemaInfo.getTable(), sql, isSuccess ? DDLInfo.DDLStatus.SUCCESS : DDLInfo.DDLStatus.FAILED, needNotifyOther);
} catch (Exception e) {
LOGGER.warn(AlarmCode.CORE_CLUSTER_WARN + "notifyResponseZKDdl error", e);
}
removeMetaLock(schemaInfo.getSchema(), schemaInfo.getTable());
}
use of com.actiontech.dble.server.util.SchemaUtil.SchemaInfo in project dble by actiontech.
the class ProxyMetaManager method alterTable.
private void alterTable(String schema, String sql, SQLAlterTableStatement alterStatement, boolean isSuccess, boolean needNotifyOther) {
SchemaInfo schemaInfo = getSchemaInfo(schema, alterStatement.getTableSource());
try {
if (!isSuccess) {
return;
}
StructureMeta.TableMeta orgTbMeta = getTableMeta(schemaInfo.getSchema(), schemaInfo.getTable());
if (orgTbMeta == null)
return;
StructureMeta.TableMeta.Builder tmBuilder = orgTbMeta.toBuilder();
List<StructureMeta.ColumnMeta> cols = new ArrayList<>();
cols.addAll(orgTbMeta.getColumnsList());
int autoColumnIndex = -1;
Set<String> indexNames = new HashSet<>();
for (StructureMeta.IndexMeta index : tmBuilder.getIndexList()) {
indexNames.add(index.getName());
}
for (SQLAlterTableItem alterItem : alterStatement.getItems()) {
if (alterItem instanceof SQLAlterTableAddColumn) {
autoColumnIndex = addColumn(tmBuilder, cols, (SQLAlterTableAddColumn) alterItem, indexNames);
} else if (alterItem instanceof SQLAlterTableAddIndex) {
addIndex(tmBuilder, (SQLAlterTableAddIndex) alterItem, indexNames);
} else if (alterItem instanceof SQLAlterTableAddConstraint) {
SQLAlterTableAddConstraint addConstraint = (SQLAlterTableAddConstraint) alterItem;
SQLConstraint constraint = addConstraint.getConstraint();
if (constraint instanceof MySqlPrimaryKey) {
MySqlPrimaryKey primaryKey = (MySqlPrimaryKey) constraint;
StructureMeta.IndexMeta indexMeta = MetaHelper.makeIndexMeta(MetaHelper.PRIMARY, IndexType.PRI, primaryKey.getColumns());
tmBuilder.setPrimary(indexMeta);
} else {
// NOT SUPPORT
}
} else if (alterItem instanceof SQLAlterTableDropIndex) {
SQLAlterTableDropIndex dropIndex = (SQLAlterTableDropIndex) alterItem;
String dropName = StringUtil.removeBackQuote(dropIndex.getIndexName().getSimpleName());
dropIndex(tmBuilder, dropName);
} else if (alterItem instanceof SQLAlterTableDropKey) {
SQLAlterTableDropKey dropIndex = (SQLAlterTableDropKey) alterItem;
String dropName = StringUtil.removeBackQuote(dropIndex.getKeyName().getSimpleName());
dropIndex(tmBuilder, dropName);
} else if (alterItem instanceof MySqlAlterTableChangeColumn) {
autoColumnIndex = changeColumn(tmBuilder, cols, (MySqlAlterTableChangeColumn) alterItem, indexNames);
} else if (alterItem instanceof MySqlAlterTableModifyColumn) {
autoColumnIndex = modifyColumn(tmBuilder, cols, (MySqlAlterTableModifyColumn) alterItem, indexNames);
} else if (alterItem instanceof SQLAlterTableDropColumnItem) {
dropColumn(cols, (SQLAlterTableDropColumnItem) alterItem);
} else if (alterItem instanceof SQLAlterTableDropPrimaryKey) {
tmBuilder.clearPrimary();
} else {
// TODO: further
}
}
tmBuilder.clearColumns().addAllColumns(cols);
if (autoColumnIndex != -1) {
tmBuilder.setAiColPos(autoColumnIndex);
}
tmBuilder.setVersion(System.currentTimeMillis());
StructureMeta.TableMeta newTblMeta = tmBuilder.build();
addTable(schemaInfo.getSchema(), newTblMeta);
} catch (Exception e) {
LOGGER.info("updateMetaData alterTable failed,sql is" + alterStatement.toString(), e);
} finally {
try {
notifyResponseClusterDDL(schemaInfo.getSchema(), schemaInfo.getTable(), sql, isSuccess ? DDLInfo.DDLStatus.SUCCESS : DDLInfo.DDLStatus.FAILED, needNotifyOther);
} catch (Exception e) {
LOGGER.warn(AlarmCode.CORE_CLUSTER_WARN + "notifyResponseZKDdl error", e);
}
removeMetaLock(schemaInfo.getSchema(), schemaInfo.getTable());
}
}
use of com.actiontech.dble.server.util.SchemaUtil.SchemaInfo in project dble by actiontech.
the class ProxyMetaManager method createTable.
private void createTable(String schema, String sql, MySqlCreateTableStatement statement, boolean isSuccess, boolean needNotifyOther) {
SchemaInfo schemaInfo = getSchemaInfo(schema, statement.getTableSource());
try {
if (!isSuccess) {
return;
}
StructureMeta.TableMeta tblMeta = MetaHelper.initTableMeta(schemaInfo.getTable(), statement, System.currentTimeMillis());
addTable(schemaInfo.getSchema(), tblMeta);
} catch (Exception e) {
LOGGER.info("updateMetaData failed,sql is" + statement.toString(), e);
} finally {
try {
notifyResponseClusterDDL(schemaInfo.getSchema(), schemaInfo.getTable(), sql, isSuccess ? DDLInfo.DDLStatus.SUCCESS : DDLInfo.DDLStatus.FAILED, needNotifyOther);
} catch (Exception e) {
LOGGER.warn(AlarmCode.CORE_CLUSTER_WARN + "notifyResponseZKDdl error", e);
}
removeMetaLock(schemaInfo.getSchema(), schemaInfo.getTable());
}
}
use of com.actiontech.dble.server.util.SchemaUtil.SchemaInfo in project dble by actiontech.
the class ProxyMetaManager method dropIndex.
private void dropIndex(String schema, String sql, SQLDropIndexStatement dropIndexStatement, boolean isSuccess, boolean needNotifyOther) {
SchemaInfo schemaInfo = getSchemaInfo(schema, dropIndexStatement.getTableName());
StructureMeta.TableMeta orgTbMeta = getTableMeta(schemaInfo.getSchema(), schemaInfo.getTable());
try {
if (!isSuccess) {
return;
}
if (orgTbMeta != null) {
StructureMeta.TableMeta.Builder tmBuilder = orgTbMeta.toBuilder();
String dropName = StringUtil.removeBackQuote(((SQLIdentifierExpr) dropIndexStatement.getIndexName()).getName());
dropIndex(tmBuilder, dropName);
}
} catch (Exception e) {
LOGGER.info("updateMetaData failed,sql is" + dropIndexStatement.toString(), e);
} finally {
try {
notifyResponseClusterDDL(schemaInfo.getSchema(), schemaInfo.getTable(), sql, isSuccess ? DDLInfo.DDLStatus.SUCCESS : DDLInfo.DDLStatus.FAILED, needNotifyOther);
} catch (Exception e) {
LOGGER.warn(AlarmCode.CORE_CLUSTER_WARN + "notifyResponseZKDdl error", e);
}
removeMetaLock(schemaInfo.getSchema(), schemaInfo.getTable());
}
}
Aggregations