[fix](catalog) do not call makeSureInitialized when create table from hms meta event (#21104)

In this PR, I remove the `makeSureInitialized()` call in `createTable()` method, because it is wrong and useless.
And also rename the methed's name to make it more clear.
This commit is contained in:
Mingyu Chen
2023-06-24 21:50:36 +08:00
committed by GitHub
parent 691a988c97
commit 5aa16e84bf
8 changed files with 19 additions and 19 deletions

View File

@ -332,12 +332,13 @@ public abstract class ExternalDatabase<T extends ExternalTable>
throw new NotImplementedException("dropTable() is not implemented");
}
public void createTable(String tableName, long tableId) {
throw new NotImplementedException("createTable() is not implemented");
}
@Override
public CatalogIf getCatalog() {
return extCatalog;
}
// Only used for sync hive metastore event
public void replayCreateTableFromEvent(String tableName, long tableId) {
throw new NotImplementedException("createTable() is not implemented");
}
}

View File

@ -74,9 +74,8 @@ public class HMSExternalDatabase extends ExternalDatabase<HMSExternalTable> {
}
@Override
public void createTable(String tableName, long tableId) {
public void replayCreateTableFromEvent(String tableName, long tableId) {
LOG.debug("create table [{}]", tableName);
makeSureInitialized();
tableNameToId.put(tableName, tableId);
HMSExternalTable table = getExternalTable(tableName, tableId, extCatalog);
idToTbl.put(tableId, table);

View File

@ -60,9 +60,8 @@ public class IcebergExternalDatabase extends ExternalDatabase<IcebergExternalTab
}
@Override
public void createTable(String tableName, long tableId) {
public void replayCreateTableFromEvent(String tableName, long tableId) {
LOG.debug("create table [{}]", tableName);
makeSureInitialized();
tableNameToId.put(tableName, tableId);
IcebergExternalTable table = new IcebergExternalTable(tableId, tableName, name,
(IcebergExternalCatalog) extCatalog);

View File

@ -60,9 +60,8 @@ public class PaimonExternalDatabase extends ExternalDatabase<PaimonExternalTable
}
@Override
public void createTable(String tableName, long tableId) {
public void replayCreateTableFromEvent(String tableName, long tableId) {
LOG.debug("create table [{}]", tableName);
makeSureInitialized();
tableNameToId.put(tableName, tableId);
PaimonExternalTable table = new PaimonExternalTable(tableId, tableName, name,
(PaimonExternalCatalog) extCatalog);

View File

@ -734,7 +734,8 @@ public class CatalogMgr implements Writable, GsonPostProcessable {
return ((ExternalCatalog) catalog).tableExistInLocal(dbName, tableName);
}
public void createExternalTable(String dbName, String tableName, String catalogName, boolean ignoreIfExists)
public void createExternalTableFromEvent(String dbName, String tableName, String catalogName,
boolean ignoreIfExists)
throws DdlException {
CatalogIf catalog = nameToCatalog.get(catalogName);
if (catalog == null) {
@ -763,11 +764,11 @@ public class CatalogMgr implements Writable, GsonPostProcessable {
log.setDbId(db.getId());
log.setTableName(tableName);
log.setTableId(Env.getCurrentEnv().getNextId());
replayCreateExternalTable(log);
replayCreateExternalTableFromEvent(log);
Env.getCurrentEnv().getEditLog().logCreateExternalTable(log);
}
public void replayCreateExternalTable(ExternalObjectLog log) {
public void replayCreateExternalTableFromEvent(ExternalObjectLog log) {
LOG.debug("ReplayCreateExternalTable,catalogId:[{}],dbId:[{}],tableId:[{}],tableName:[{}]", log.getCatalogId(),
log.getDbId(), log.getTableId(), log.getTableName());
ExternalCatalog catalog = (ExternalCatalog) idToCatalog.get(log.getCatalogId());
@ -782,7 +783,7 @@ public class CatalogMgr implements Writable, GsonPostProcessable {
}
db.writeLock();
try {
db.createTable(log.getTableName(), log.getTableId());
db.replayCreateTableFromEvent(log.getTableName(), log.getTableId());
} finally {
db.writeUnlock();
}

View File

@ -73,9 +73,9 @@ public class AlterTableEvent extends MetastoreTableEvent {
return;
}
Env.getCurrentEnv().getCatalogMgr()
.dropExternalTable(tableBefore.getDbName(), tableBefore.getTableName(), catalogName, true);
.dropExternalTable(tableBefore.getDbName(), tableBefore.getTableName(), catalogName, true);
Env.getCurrentEnv().getCatalogMgr()
.createExternalTable(tableAfter.getDbName(), tableAfter.getTableName(), catalogName, true);
.createExternalTableFromEvent(tableAfter.getDbName(), tableAfter.getTableName(), catalogName, true);
}
private void processRename() throws DdlException {
@ -93,7 +93,7 @@ public class AlterTableEvent extends MetastoreTableEvent {
Env.getCurrentEnv().getCatalogMgr()
.dropExternalTable(tableBefore.getDbName(), tableBefore.getTableName(), catalogName, true);
Env.getCurrentEnv().getCatalogMgr()
.createExternalTable(tableAfter.getDbName(), tableAfter.getTableName(), catalogName, true);
.createExternalTableFromEvent(tableAfter.getDbName(), tableAfter.getTableName(), catalogName, true);
}

View File

@ -59,7 +59,8 @@ public class CreateTableEvent extends MetastoreTableEvent {
protected void process() throws MetastoreNotificationException {
try {
infoLog("catalogName:[{}],dbName:[{}],tableName:[{}]", catalogName, dbName, tblName);
Env.getCurrentEnv().getCatalogMgr().createExternalTable(dbName, hmsTbl.getTableName(), catalogName, true);
Env.getCurrentEnv().getCatalogMgr()
.createExternalTableFromEvent(dbName, hmsTbl.getTableName(), catalogName, true);
} catch (DdlException e) {
throw new MetastoreNotificationException(
debugString("Failed to process event"), e);

View File

@ -960,7 +960,7 @@ public class EditLog {
}
case OperationType.OP_CREATE_EXTERNAL_TABLE: {
final ExternalObjectLog log = (ExternalObjectLog) journal.getData();
env.getCatalogMgr().replayCreateExternalTable(log);
env.getCatalogMgr().replayCreateExternalTableFromEvent(log);
break;
}
case OperationType.OP_DROP_EXTERNAL_DB: {