public boolean createTableWithLock(Table table, boolean isReplay) {
writeLock();
try {
String tableName = table.getName();
if (nameToTable.containsKey(tableName)) {
return false;
} else {
idToTable.put(table.getId(), table);
nameToTable.put(table.getName(), table);
//if (true) {
// throw new RuntimeException("mock exception");
// }
if (!isReplay) {
// Write edit log
CreateTableInfo info = new CreateTableInfo(fullQualifiedName, table);
GlobalStateMgr.getCurrentState().getEditLog().logCreateTable(info);
}
table.onCreate();
}
return true;
} finally {
writeUnlock();
}
}
为什么starrock 基本所有的状态变更的操作都是 先进行内存变更,再写editlog。 如果写editlog失败,会导致内存中的状态变更仍然是生效的。 比如我把上述代码里的注释去掉,就会出现starrock建表失败,但showtable 看到table, 然后重启又看不见该表。