[Enhencement](binlog) db enable binlog (#22256)
* Improve db update binlog properties (binlog.enable = "true") with check all table enable binlog * Add more test_alter_database_property regression test
This commit is contained in:
@ -179,4 +179,10 @@ public class BinlogConfig implements Writable {
|
||||
sb.append(",\n\"").append(PropertyAnalyzer.PROPERTIES_BINLOG_MAX_HISTORY_NUMS).append("\" = \"")
|
||||
.append(maxHistoryNums).append("\"");
|
||||
}
|
||||
|
||||
public static BinlogConfig fromProperties(Map<String, String> properties) {
|
||||
BinlogConfig binlogConfig = new BinlogConfig();
|
||||
binlogConfig.mergeFromProperties(properties);
|
||||
return binlogConfig;
|
||||
}
|
||||
}
|
||||
|
||||
@ -854,11 +854,43 @@ public class Database extends MetaObject implements Writable, DatabaseIf<Table>
|
||||
return new HashMap<>(idToTable);
|
||||
}
|
||||
|
||||
public void updateDbProperties(Map<String, String> properties) {
|
||||
public void replayUpdateDbProperties(Map<String, String> properties) {
|
||||
dbProperties.updateProperties(properties);
|
||||
binlogConfig = dbProperties.getBinlogConfig();
|
||||
}
|
||||
|
||||
public boolean updateDbProperties(Map<String, String> properties) throws DdlException {
|
||||
BinlogConfig oldBinlogConfig = getBinlogConfig();
|
||||
BinlogConfig newBinlogConfig = BinlogConfig.fromProperties(properties);
|
||||
if (oldBinlogConfig.equals(newBinlogConfig)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (newBinlogConfig.isEnable() && !oldBinlogConfig.isEnable()) {
|
||||
// check all tables binlog enable is true
|
||||
for (Table table : idToTable.values()) {
|
||||
if (table.getType() != TableType.OLAP) {
|
||||
continue;
|
||||
}
|
||||
|
||||
OlapTable olapTable = (OlapTable) table;
|
||||
olapTable.readLock();
|
||||
try {
|
||||
if (!olapTable.getBinlogConfig().isEnable()) {
|
||||
String errMsg = String.format("binlog is not enable in table[%s] in db [%s]", table.getName(),
|
||||
getFullName());
|
||||
throw new DdlException(errMsg);
|
||||
}
|
||||
} finally {
|
||||
olapTable.readUnlock();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
replayUpdateDbProperties(properties);
|
||||
return true;
|
||||
}
|
||||
|
||||
public BinlogConfig getBinlogConfig() {
|
||||
return binlogConfig;
|
||||
}
|
||||
|
||||
@ -763,7 +763,10 @@ public class InternalCatalog implements CatalogIf<Database> {
|
||||
|
||||
db.writeLockOrDdlException();
|
||||
try {
|
||||
db.updateDbProperties(properties);
|
||||
boolean update = db.updateDbProperties(properties);
|
||||
if (!update) {
|
||||
return;
|
||||
}
|
||||
|
||||
AlterDatabasePropertyInfo info = new AlterDatabasePropertyInfo(dbName, properties);
|
||||
Env.getCurrentEnv().getEditLog().logAlterDatabaseProperty(info);
|
||||
@ -777,7 +780,7 @@ public class InternalCatalog implements CatalogIf<Database> {
|
||||
Database db = (Database) getDbOrMetaException(dbName);
|
||||
db.writeLock();
|
||||
try {
|
||||
db.updateDbProperties(properties);
|
||||
db.replayUpdateDbProperties(properties);
|
||||
} finally {
|
||||
db.writeUnlock();
|
||||
}
|
||||
|
||||
@ -62,4 +62,8 @@ public class AlterDatabasePropertyInfo implements Writable {
|
||||
public static AlterDatabasePropertyInfo read(DataInput in) throws IOException {
|
||||
return GsonUtils.GSON.fromJson(Text.readString(in), AlterDatabasePropertyInfo.class);
|
||||
}
|
||||
|
||||
public String toJson() {
|
||||
return GsonUtils.GSON.toJson(this);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user