[enhancement](binlog) CreateTable inherit db binlog && Add some checks (#22293)
This commit is contained in:
@ -2799,7 +2799,6 @@ public class SchemaChangeHandler extends AlterHandler {
|
||||
|
||||
public boolean updateBinlogConfig(Database db, OlapTable olapTable, List<AlterClause> alterClauses)
|
||||
throws DdlException, UserException {
|
||||
// TODO(Drogon): check olapTable read binlog thread safety
|
||||
List<Partition> partitions = Lists.newArrayList();
|
||||
BinlogConfig oldBinlogConfig;
|
||||
BinlogConfig newBinlogConfig;
|
||||
|
||||
@ -269,6 +269,9 @@ public class CreateTableStmt extends DdlStmt {
|
||||
}
|
||||
|
||||
public Map<String, String> getProperties() {
|
||||
if (this.properties == null) {
|
||||
this.properties = Maps.newHashMap();
|
||||
}
|
||||
return this.properties;
|
||||
}
|
||||
|
||||
|
||||
@ -64,6 +64,10 @@ public class BinlogConfig implements Writable {
|
||||
}
|
||||
|
||||
public void mergeFromProperties(Map<String, String> properties) {
|
||||
if (properties == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (properties.containsKey(PropertyAnalyzer.PROPERTIES_BINLOG_ENABLE)) {
|
||||
enable = Boolean.parseBoolean(properties.get(
|
||||
PropertyAnalyzer.PROPERTIES_BINLOG_ENABLE));
|
||||
|
||||
@ -1889,6 +1889,20 @@ public class InternalCatalog implements CatalogIf<Database> {
|
||||
String tableName = stmt.getTableName();
|
||||
LOG.debug("begin create olap table: {}", tableName);
|
||||
|
||||
BinlogConfig dbBinlogConfig;
|
||||
db.readLock();
|
||||
try {
|
||||
dbBinlogConfig = new BinlogConfig(db.getBinlogConfig());
|
||||
} finally {
|
||||
db.readUnlock();
|
||||
}
|
||||
BinlogConfig createTableBinlogConfig = new BinlogConfig(dbBinlogConfig);
|
||||
createTableBinlogConfig.mergeFromProperties(stmt.getProperties());
|
||||
if (dbBinlogConfig.isEnable() && !createTableBinlogConfig.isEnable()) {
|
||||
throw new DdlException("Cannot create table with binlog disabled when database binlog enable");
|
||||
}
|
||||
stmt.getProperties().putAll(createTableBinlogConfig.toProperties());
|
||||
|
||||
// get keys type
|
||||
KeysDesc keysDesc = stmt.getKeysDesc();
|
||||
Preconditions.checkNotNull(keysDesc);
|
||||
|
||||
@ -111,7 +111,7 @@ public class CreateTableStmtTest {
|
||||
stmt.analyze(analyzer);
|
||||
Assert.assertEquals("testCluster:db1", stmt.getDbName());
|
||||
Assert.assertEquals("table1", stmt.getTableName());
|
||||
Assert.assertNull(stmt.getProperties());
|
||||
Assert.assertTrue(stmt.getProperties() == null || stmt.getProperties().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -121,7 +121,7 @@ public class CreateTableStmtTest {
|
||||
stmt.analyze(analyzer);
|
||||
Assert.assertEquals("testCluster:db1", stmt.getDbName());
|
||||
Assert.assertEquals("table1", stmt.getTableName());
|
||||
Assert.assertNull(stmt.getProperties());
|
||||
Assert.assertTrue(stmt.getProperties() == null || stmt.getProperties().isEmpty());
|
||||
Assert.assertTrue(stmt.toSql().contains("DISTRIBUTED BY RANDOM\nBUCKETS 6"));
|
||||
}
|
||||
|
||||
@ -242,7 +242,7 @@ public class CreateTableStmtTest {
|
||||
stmt.analyze(analyzer);
|
||||
Assert.assertEquals("testCluster:db1", stmt.getDbName());
|
||||
Assert.assertEquals("table1", stmt.getTableName());
|
||||
Assert.assertNull(stmt.getProperties());
|
||||
Assert.assertTrue(stmt.getProperties() == null || stmt.getProperties().isEmpty());
|
||||
Assert.assertTrue(stmt.toSql()
|
||||
.contains("rollup( `index1` (`col1`, `col2`) FROM `table1`, `index2` (`col2`, `col3`) FROM `table1`)"));
|
||||
}
|
||||
@ -256,7 +256,7 @@ public class CreateTableStmtTest {
|
||||
Assert.assertEquals("testDb", stmt.getDbName());
|
||||
Assert.assertEquals("table1", stmt.getTableName());
|
||||
Assert.assertNull(stmt.getPartitionDesc());
|
||||
Assert.assertNull(stmt.getProperties());
|
||||
Assert.assertTrue(stmt.getProperties() == null || stmt.getProperties().isEmpty());
|
||||
}
|
||||
|
||||
@Test(expected = AnalysisException.class)
|
||||
|
||||
Reference in New Issue
Block a user