[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:
Jack Drogon
2023-07-27 10:03:51 +08:00
committed by GitHub
parent 341c45974c
commit 052a416d49
5 changed files with 106 additions and 3 deletions

View File

@ -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;
}
}

View File

@ -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;
}

View File

@ -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();
}

View File

@ -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);
}
}