morningman commented on code in PR #15702: URL: https://github.com/apache/doris/pull/15702#discussion_r1066750349
########## fe/fe-core/src/main/java/org/apache/doris/datasource/CatalogMgr.java: ########## @@ -544,6 +544,28 @@ public void replayRefreshExternalDb(ExternalObjectLog log) { } } + public void refreshExternalTable(String dbName, String tableName, String catalogName) throws DdlException { Review Comment: We had a same method in `RefreshManager`, called `refreshExternalCtlTable()`, why not using that? ########## fe/fe-core/src/main/java/org/apache/doris/datasource/CatalogMgr.java: ########## @@ -583,11 +605,251 @@ public void replayDropExternalTable(ExternalObjectLog log) { ExternalCatalog catalog = (ExternalCatalog) idToCatalog.get(log.getCatalogId()); ExternalDatabase db = catalog.getDbForReplay(log.getDbId()); ExternalTable table = db.getTableForReplay(log.getTableId()); - db.dropTable(table.getName()); + db.writeLock(); + try { + db.dropTable(table.getName()); + } finally { + db.writeUnlock(); + } + Env.getCurrentEnv().getExtMetaCacheMgr() .invalidateTableCache(catalog.getId(), db.getFullName(), table.getName()); } + public boolean externalTableExistInLocal(String dbName, String tableName, String catalogName) throws DdlException { + CatalogIf catalog = nameToCatalog.get(catalogName); + if (catalog == null) { + throw new DdlException("No catalog found with name: " + catalogName); + } + if (!(catalog instanceof ExternalCatalog)) { + throw new DdlException("Only support ExternalCatalog Tables"); + } + return ((ExternalCatalog) catalog).tableExistInLocal(dbName, tableName); + } + + public void createExternalTable(String dbName, String tableName, String catalogName) throws DdlException { + CatalogIf catalog = nameToCatalog.get(catalogName); + if (catalog == null) { + throw new DdlException("No catalog found with name: " + catalogName); + } + if (!(catalog instanceof ExternalCatalog)) { + throw new DdlException("Only support create ExternalCatalog Tables"); + } + DatabaseIf db = catalog.getDbNullable(dbName); + if (db == null) { + throw new DdlException("Database " + dbName + " does not exist in catalog " + catalog.getName()); + } + + TableIf table = db.getTableNullable(tableName); + if (table != null) { + throw new DdlException("Table " + tableName + " has exist in db " + dbName); + } + ExternalObjectLog log = new ExternalObjectLog(); + log.setCatalogId(catalog.getId()); + log.setDbId(db.getId()); + log.setTableName(tableName); + log.setTableId(Env.getCurrentEnv().getNextId()); + replayCreateExternalTable(log); + Env.getCurrentEnv().getEditLog().logCreateExternalTable(log); + } + + public void replayCreateExternalTable(ExternalObjectLog log) { + LOG.debug("ReplayCreateExternalTable,catalogId:[{}],dbId:[{}],tableId:[{}],tableName:[{}]", log.getCatalogId(), + log.getDbId(), log.getTableId(), log.getTableName()); + ExternalCatalog catalog = (ExternalCatalog) idToCatalog.get(log.getCatalogId()); Review Comment: Check if `catalog` is null, just return. Same for the following `db` ########## fe/fe-core/src/main/java/org/apache/doris/datasource/CatalogMgr.java: ########## @@ -583,11 +605,251 @@ public void replayDropExternalTable(ExternalObjectLog log) { ExternalCatalog catalog = (ExternalCatalog) idToCatalog.get(log.getCatalogId()); ExternalDatabase db = catalog.getDbForReplay(log.getDbId()); ExternalTable table = db.getTableForReplay(log.getTableId()); - db.dropTable(table.getName()); + db.writeLock(); + try { + db.dropTable(table.getName()); + } finally { + db.writeUnlock(); + } + Env.getCurrentEnv().getExtMetaCacheMgr() .invalidateTableCache(catalog.getId(), db.getFullName(), table.getName()); } + public boolean externalTableExistInLocal(String dbName, String tableName, String catalogName) throws DdlException { + CatalogIf catalog = nameToCatalog.get(catalogName); + if (catalog == null) { + throw new DdlException("No catalog found with name: " + catalogName); + } + if (!(catalog instanceof ExternalCatalog)) { + throw new DdlException("Only support ExternalCatalog Tables"); + } + return ((ExternalCatalog) catalog).tableExistInLocal(dbName, tableName); + } + + public void createExternalTable(String dbName, String tableName, String catalogName) throws DdlException { + CatalogIf catalog = nameToCatalog.get(catalogName); + if (catalog == null) { + throw new DdlException("No catalog found with name: " + catalogName); + } + if (!(catalog instanceof ExternalCatalog)) { + throw new DdlException("Only support create ExternalCatalog Tables"); + } + DatabaseIf db = catalog.getDbNullable(dbName); + if (db == null) { + throw new DdlException("Database " + dbName + " does not exist in catalog " + catalog.getName()); + } + + TableIf table = db.getTableNullable(tableName); + if (table != null) { + throw new DdlException("Table " + tableName + " has exist in db " + dbName); + } + ExternalObjectLog log = new ExternalObjectLog(); + log.setCatalogId(catalog.getId()); + log.setDbId(db.getId()); + log.setTableName(tableName); + log.setTableId(Env.getCurrentEnv().getNextId()); + replayCreateExternalTable(log); + Env.getCurrentEnv().getEditLog().logCreateExternalTable(log); + } + + public void replayCreateExternalTable(ExternalObjectLog log) { + LOG.debug("ReplayCreateExternalTable,catalogId:[{}],dbId:[{}],tableId:[{}],tableName:[{}]", log.getCatalogId(), + log.getDbId(), log.getTableId(), log.getTableName()); + ExternalCatalog catalog = (ExternalCatalog) idToCatalog.get(log.getCatalogId()); + ExternalDatabase db = catalog.getDbForReplay(log.getDbId()); + db.writeLock(); + try { + db.createTable(log.getTableName(), log.getTableId()); + } finally { + db.writeUnlock(); + } + } + + public void dropExternalDatabase(String dbName, String catalogName) throws DdlException { + CatalogIf catalog = nameToCatalog.get(catalogName); + if (catalog == null) { + throw new DdlException("No catalog found with name: " + catalogName); + } + if (!(catalog instanceof ExternalCatalog)) { + throw new DdlException("Only support drop ExternalCatalog databases"); + } + DatabaseIf db = catalog.getDbNullable(dbName); + if (db == null) { + throw new DdlException("Database " + dbName + " does not exist in catalog " + catalog.getName()); + } + + ExternalObjectLog log = new ExternalObjectLog(); + log.setCatalogId(catalog.getId()); + log.setDbId(db.getId()); + log.setInvalidCache(true); + replayDropExternalDatabase(log); + Env.getCurrentEnv().getEditLog().logDropExternalDatabase(log); + } + + public void replayDropExternalDatabase(ExternalObjectLog log) { + writeLock(); + try { + LOG.debug("ReplayDropExternalTable,catalogId:[{}],dbId:[{}],tableId:[{}]", log.getCatalogId(), + log.getDbId(), log.getTableId()); + ExternalCatalog catalog = (ExternalCatalog) idToCatalog.get(log.getCatalogId()); + ExternalDatabase db = catalog.getDbForReplay(log.getDbId()); + catalog.dropDatabase(db.getFullName()); + Env.getCurrentEnv().getExtMetaCacheMgr().invalidateDbCache(catalog.getId(), db.getFullName()); + } finally { + writeUnlock(); + } + } + + public void createExternalDatabase(String dbName, String catalogName) throws DdlException { + CatalogIf catalog = nameToCatalog.get(catalogName); + if (catalog == null) { + throw new DdlException("No catalog found with name: " + catalogName); + } + if (!(catalog instanceof ExternalCatalog)) { + throw new DdlException("Only support create ExternalCatalog databases"); + } + DatabaseIf db = catalog.getDbNullable(dbName); + if (db != null) { + throw new DdlException("Database " + dbName + " has exist in catalog " + catalog.getName()); + } + + ExternalObjectLog log = new ExternalObjectLog(); + log.setCatalogId(catalog.getId()); + log.setDbId(Env.getCurrentEnv().getNextId()); + log.setDbName(dbName); + replayCreateExternalDatabase(log); + Env.getCurrentEnv().getEditLog().logCreateExternalDatabase(log); + } + + public void replayCreateExternalDatabase(ExternalObjectLog log) { + writeLock(); + try { + LOG.debug("ReplayCreateExternalDatabase,catalogId:[{}],dbId:[{}],dbName:[{}]", log.getCatalogId(), + log.getDbId(), log.getDbName()); + ExternalCatalog catalog = (ExternalCatalog) idToCatalog.get(log.getCatalogId()); Review Comment: Ditto ########## fe/fe-core/src/main/java/org/apache/doris/datasource/CatalogMgr.java: ########## @@ -583,11 +605,251 @@ public void replayDropExternalTable(ExternalObjectLog log) { ExternalCatalog catalog = (ExternalCatalog) idToCatalog.get(log.getCatalogId()); ExternalDatabase db = catalog.getDbForReplay(log.getDbId()); ExternalTable table = db.getTableForReplay(log.getTableId()); - db.dropTable(table.getName()); + db.writeLock(); + try { + db.dropTable(table.getName()); + } finally { + db.writeUnlock(); + } + Env.getCurrentEnv().getExtMetaCacheMgr() .invalidateTableCache(catalog.getId(), db.getFullName(), table.getName()); } + public boolean externalTableExistInLocal(String dbName, String tableName, String catalogName) throws DdlException { + CatalogIf catalog = nameToCatalog.get(catalogName); + if (catalog == null) { + throw new DdlException("No catalog found with name: " + catalogName); + } + if (!(catalog instanceof ExternalCatalog)) { + throw new DdlException("Only support ExternalCatalog Tables"); + } + return ((ExternalCatalog) catalog).tableExistInLocal(dbName, tableName); + } + + public void createExternalTable(String dbName, String tableName, String catalogName) throws DdlException { + CatalogIf catalog = nameToCatalog.get(catalogName); + if (catalog == null) { + throw new DdlException("No catalog found with name: " + catalogName); + } + if (!(catalog instanceof ExternalCatalog)) { + throw new DdlException("Only support create ExternalCatalog Tables"); + } + DatabaseIf db = catalog.getDbNullable(dbName); + if (db == null) { + throw new DdlException("Database " + dbName + " does not exist in catalog " + catalog.getName()); + } + + TableIf table = db.getTableNullable(tableName); + if (table != null) { + throw new DdlException("Table " + tableName + " has exist in db " + dbName); + } + ExternalObjectLog log = new ExternalObjectLog(); + log.setCatalogId(catalog.getId()); + log.setDbId(db.getId()); + log.setTableName(tableName); + log.setTableId(Env.getCurrentEnv().getNextId()); + replayCreateExternalTable(log); + Env.getCurrentEnv().getEditLog().logCreateExternalTable(log); + } + + public void replayCreateExternalTable(ExternalObjectLog log) { + LOG.debug("ReplayCreateExternalTable,catalogId:[{}],dbId:[{}],tableId:[{}],tableName:[{}]", log.getCatalogId(), + log.getDbId(), log.getTableId(), log.getTableName()); + ExternalCatalog catalog = (ExternalCatalog) idToCatalog.get(log.getCatalogId()); + ExternalDatabase db = catalog.getDbForReplay(log.getDbId()); + db.writeLock(); + try { + db.createTable(log.getTableName(), log.getTableId()); + } finally { + db.writeUnlock(); + } + } + + public void dropExternalDatabase(String dbName, String catalogName) throws DdlException { + CatalogIf catalog = nameToCatalog.get(catalogName); + if (catalog == null) { + throw new DdlException("No catalog found with name: " + catalogName); + } + if (!(catalog instanceof ExternalCatalog)) { + throw new DdlException("Only support drop ExternalCatalog databases"); + } + DatabaseIf db = catalog.getDbNullable(dbName); + if (db == null) { + throw new DdlException("Database " + dbName + " does not exist in catalog " + catalog.getName()); + } + + ExternalObjectLog log = new ExternalObjectLog(); + log.setCatalogId(catalog.getId()); + log.setDbId(db.getId()); + log.setInvalidCache(true); + replayDropExternalDatabase(log); + Env.getCurrentEnv().getEditLog().logDropExternalDatabase(log); + } + + public void replayDropExternalDatabase(ExternalObjectLog log) { + writeLock(); + try { + LOG.debug("ReplayDropExternalTable,catalogId:[{}],dbId:[{}],tableId:[{}]", log.getCatalogId(), + log.getDbId(), log.getTableId()); + ExternalCatalog catalog = (ExternalCatalog) idToCatalog.get(log.getCatalogId()); + ExternalDatabase db = catalog.getDbForReplay(log.getDbId()); + catalog.dropDatabase(db.getFullName()); + Env.getCurrentEnv().getExtMetaCacheMgr().invalidateDbCache(catalog.getId(), db.getFullName()); + } finally { + writeUnlock(); + } + } + + public void createExternalDatabase(String dbName, String catalogName) throws DdlException { + CatalogIf catalog = nameToCatalog.get(catalogName); + if (catalog == null) { + throw new DdlException("No catalog found with name: " + catalogName); + } + if (!(catalog instanceof ExternalCatalog)) { + throw new DdlException("Only support create ExternalCatalog databases"); + } + DatabaseIf db = catalog.getDbNullable(dbName); + if (db != null) { + throw new DdlException("Database " + dbName + " has exist in catalog " + catalog.getName()); + } + + ExternalObjectLog log = new ExternalObjectLog(); + log.setCatalogId(catalog.getId()); + log.setDbId(Env.getCurrentEnv().getNextId()); + log.setDbName(dbName); + replayCreateExternalDatabase(log); + Env.getCurrentEnv().getEditLog().logCreateExternalDatabase(log); + } + + public void replayCreateExternalDatabase(ExternalObjectLog log) { + writeLock(); + try { + LOG.debug("ReplayCreateExternalDatabase,catalogId:[{}],dbId:[{}],dbName:[{}]", log.getCatalogId(), + log.getDbId(), log.getDbName()); + ExternalCatalog catalog = (ExternalCatalog) idToCatalog.get(log.getCatalogId()); + catalog.createDatabase(log.getDbId(), log.getDbName()); + } finally { + writeUnlock(); + } + } + + public void addExternalPartitions(String catalogName, String dbName, String tableName, List<String> partitionNames) + throws DdlException { + CatalogIf catalog = nameToCatalog.get(catalogName); + if (catalog == null) { + throw new DdlException("No catalog found with name: " + catalogName); + } + if (!(catalog instanceof ExternalCatalog)) { + throw new DdlException("Only support ExternalCatalog"); + } + DatabaseIf db = catalog.getDbNullable(dbName); + if (db == null) { + throw new DdlException("Database " + dbName + " does not exist in catalog " + catalog.getName()); + } + + TableIf table = db.getTableNullable(tableName); + if (table == null) { + throw new DdlException("Table " + tableName + " does not exist in db " + dbName); + } + + ExternalObjectLog log = new ExternalObjectLog(); + log.setCatalogId(catalog.getId()); + log.setDbId(db.getId()); + log.setTableId(table.getId()); + log.setPartitionNames(partitionNames); + replayAddExternalPartitions(log); + Env.getCurrentEnv().getEditLog().logAddExternalPartitions(log); + } + + public void replayAddExternalPartitions(ExternalObjectLog log) { + LOG.debug("ReplayAddExternalPartitions,catalogId:[{}],dbId:[{}],tableId:[{}]", log.getCatalogId(), + log.getDbId(), log.getTableId()); + ExternalCatalog catalog = (ExternalCatalog) idToCatalog.get(log.getCatalogId()); + ExternalDatabase db = catalog.getDbForReplay(log.getDbId()); + ExternalTable table = db.getTableForReplay(log.getTableId()); + Env.getCurrentEnv().getExtMetaCacheMgr() + .addPartitionsCache(catalog.getId(), table, log.getPartitionNames()); + } + + public void dropExternalPartitions(String catalogName, String dbName, String tableName, List<String> partitionNames) + throws DdlException { + CatalogIf catalog = nameToCatalog.get(catalogName); + if (catalog == null) { + throw new DdlException("No catalog found with name: " + catalogName); + } + if (!(catalog instanceof ExternalCatalog)) { + throw new DdlException("Only support ExternalCatalog"); + } + DatabaseIf db = catalog.getDbNullable(dbName); + if (db == null) { + throw new DdlException("Database " + dbName + " does not exist in catalog " + catalog.getName()); + } + + TableIf table = db.getTableNullable(tableName); + if (table == null) { + throw new DdlException("Table " + tableName + " does not exist in db " + dbName); + } + + ExternalObjectLog log = new ExternalObjectLog(); + log.setCatalogId(catalog.getId()); + log.setDbId(db.getId()); + log.setTableId(table.getId()); + log.setPartitionNames(partitionNames); + replayDropExternalPartitions(log); + Env.getCurrentEnv().getEditLog().logDropExternalPartitions(log); + } + + public void replayDropExternalPartitions(ExternalObjectLog log) { + LOG.debug("ReplayDropExternalPartitions,catalogId:[{}],dbId:[{}],tableId:[{}]", log.getCatalogId(), + log.getDbId(), log.getTableId()); + ExternalCatalog catalog = (ExternalCatalog) idToCatalog.get(log.getCatalogId()); + ExternalDatabase db = catalog.getDbForReplay(log.getDbId()); + ExternalTable table = db.getTableForReplay(log.getTableId()); + Env.getCurrentEnv().getExtMetaCacheMgr() + .dropPartitionsCache(catalog.getId(), table, log.getPartitionNames()); + } + + public void refreshExternalPartitions(String catalogName, String dbName, String tableName, + List<String> partitionNames) + throws DdlException { + CatalogIf catalog = nameToCatalog.get(catalogName); + if (catalog == null) { + throw new DdlException("No catalog found with name: " + catalogName); + } + if (!(catalog instanceof ExternalCatalog)) { + throw new DdlException("Only support ExternalCatalog"); + } + DatabaseIf db = catalog.getDbNullable(dbName); + if (db == null) { + throw new DdlException("Database " + dbName + " does not exist in catalog " + catalog.getName()); + } + + TableIf table = db.getTableNullable(tableName); + if (table == null) { + throw new DdlException("Table " + tableName + " does not exist in db " + dbName); + } + + ExternalObjectLog log = new ExternalObjectLog(); + log.setCatalogId(catalog.getId()); + log.setDbId(db.getId()); + log.setTableId(table.getId()); + log.setPartitionNames(partitionNames); + replayRefreshExternalPartitions(log); + Env.getCurrentEnv().getEditLog().logInvalidateExternalPartitions(log); + } + + public void replayRefreshExternalPartitions(ExternalObjectLog log) { + LOG.debug("replayRefreshExternalPartitions,catalogId:[{}],dbId:[{}],tableId:[{}]", log.getCatalogId(), + log.getDbId(), log.getTableId()); + ExternalCatalog catalog = (ExternalCatalog) idToCatalog.get(log.getCatalogId()); Review Comment: Ditto ########## fe/fe-core/src/main/java/org/apache/doris/datasource/CatalogMgr.java: ########## @@ -583,11 +605,251 @@ public void replayDropExternalTable(ExternalObjectLog log) { ExternalCatalog catalog = (ExternalCatalog) idToCatalog.get(log.getCatalogId()); ExternalDatabase db = catalog.getDbForReplay(log.getDbId()); ExternalTable table = db.getTableForReplay(log.getTableId()); - db.dropTable(table.getName()); + db.writeLock(); + try { + db.dropTable(table.getName()); + } finally { + db.writeUnlock(); + } + Env.getCurrentEnv().getExtMetaCacheMgr() .invalidateTableCache(catalog.getId(), db.getFullName(), table.getName()); } + public boolean externalTableExistInLocal(String dbName, String tableName, String catalogName) throws DdlException { + CatalogIf catalog = nameToCatalog.get(catalogName); + if (catalog == null) { + throw new DdlException("No catalog found with name: " + catalogName); + } + if (!(catalog instanceof ExternalCatalog)) { + throw new DdlException("Only support ExternalCatalog Tables"); + } + return ((ExternalCatalog) catalog).tableExistInLocal(dbName, tableName); + } + + public void createExternalTable(String dbName, String tableName, String catalogName) throws DdlException { + CatalogIf catalog = nameToCatalog.get(catalogName); + if (catalog == null) { + throw new DdlException("No catalog found with name: " + catalogName); + } + if (!(catalog instanceof ExternalCatalog)) { + throw new DdlException("Only support create ExternalCatalog Tables"); + } + DatabaseIf db = catalog.getDbNullable(dbName); + if (db == null) { + throw new DdlException("Database " + dbName + " does not exist in catalog " + catalog.getName()); + } + + TableIf table = db.getTableNullable(tableName); + if (table != null) { + throw new DdlException("Table " + tableName + " has exist in db " + dbName); + } + ExternalObjectLog log = new ExternalObjectLog(); + log.setCatalogId(catalog.getId()); + log.setDbId(db.getId()); + log.setTableName(tableName); + log.setTableId(Env.getCurrentEnv().getNextId()); + replayCreateExternalTable(log); + Env.getCurrentEnv().getEditLog().logCreateExternalTable(log); + } + + public void replayCreateExternalTable(ExternalObjectLog log) { + LOG.debug("ReplayCreateExternalTable,catalogId:[{}],dbId:[{}],tableId:[{}],tableName:[{}]", log.getCatalogId(), + log.getDbId(), log.getTableId(), log.getTableName()); + ExternalCatalog catalog = (ExternalCatalog) idToCatalog.get(log.getCatalogId()); + ExternalDatabase db = catalog.getDbForReplay(log.getDbId()); + db.writeLock(); + try { + db.createTable(log.getTableName(), log.getTableId()); + } finally { + db.writeUnlock(); + } + } + + public void dropExternalDatabase(String dbName, String catalogName) throws DdlException { + CatalogIf catalog = nameToCatalog.get(catalogName); + if (catalog == null) { + throw new DdlException("No catalog found with name: " + catalogName); + } + if (!(catalog instanceof ExternalCatalog)) { + throw new DdlException("Only support drop ExternalCatalog databases"); + } + DatabaseIf db = catalog.getDbNullable(dbName); + if (db == null) { + throw new DdlException("Database " + dbName + " does not exist in catalog " + catalog.getName()); + } + + ExternalObjectLog log = new ExternalObjectLog(); + log.setCatalogId(catalog.getId()); + log.setDbId(db.getId()); + log.setInvalidCache(true); + replayDropExternalDatabase(log); + Env.getCurrentEnv().getEditLog().logDropExternalDatabase(log); + } + + public void replayDropExternalDatabase(ExternalObjectLog log) { + writeLock(); + try { + LOG.debug("ReplayDropExternalTable,catalogId:[{}],dbId:[{}],tableId:[{}]", log.getCatalogId(), + log.getDbId(), log.getTableId()); + ExternalCatalog catalog = (ExternalCatalog) idToCatalog.get(log.getCatalogId()); + ExternalDatabase db = catalog.getDbForReplay(log.getDbId()); + catalog.dropDatabase(db.getFullName()); + Env.getCurrentEnv().getExtMetaCacheMgr().invalidateDbCache(catalog.getId(), db.getFullName()); + } finally { + writeUnlock(); + } + } + + public void createExternalDatabase(String dbName, String catalogName) throws DdlException { + CatalogIf catalog = nameToCatalog.get(catalogName); + if (catalog == null) { + throw new DdlException("No catalog found with name: " + catalogName); + } + if (!(catalog instanceof ExternalCatalog)) { + throw new DdlException("Only support create ExternalCatalog databases"); + } + DatabaseIf db = catalog.getDbNullable(dbName); + if (db != null) { + throw new DdlException("Database " + dbName + " has exist in catalog " + catalog.getName()); + } + + ExternalObjectLog log = new ExternalObjectLog(); + log.setCatalogId(catalog.getId()); + log.setDbId(Env.getCurrentEnv().getNextId()); + log.setDbName(dbName); + replayCreateExternalDatabase(log); + Env.getCurrentEnv().getEditLog().logCreateExternalDatabase(log); + } + + public void replayCreateExternalDatabase(ExternalObjectLog log) { + writeLock(); + try { + LOG.debug("ReplayCreateExternalDatabase,catalogId:[{}],dbId:[{}],dbName:[{}]", log.getCatalogId(), + log.getDbId(), log.getDbName()); + ExternalCatalog catalog = (ExternalCatalog) idToCatalog.get(log.getCatalogId()); + catalog.createDatabase(log.getDbId(), log.getDbName()); + } finally { + writeUnlock(); + } + } + + public void addExternalPartitions(String catalogName, String dbName, String tableName, List<String> partitionNames) + throws DdlException { + CatalogIf catalog = nameToCatalog.get(catalogName); + if (catalog == null) { + throw new DdlException("No catalog found with name: " + catalogName); + } + if (!(catalog instanceof ExternalCatalog)) { + throw new DdlException("Only support ExternalCatalog"); + } + DatabaseIf db = catalog.getDbNullable(dbName); + if (db == null) { + throw new DdlException("Database " + dbName + " does not exist in catalog " + catalog.getName()); + } + + TableIf table = db.getTableNullable(tableName); + if (table == null) { + throw new DdlException("Table " + tableName + " does not exist in db " + dbName); + } + + ExternalObjectLog log = new ExternalObjectLog(); + log.setCatalogId(catalog.getId()); + log.setDbId(db.getId()); + log.setTableId(table.getId()); + log.setPartitionNames(partitionNames); + replayAddExternalPartitions(log); + Env.getCurrentEnv().getEditLog().logAddExternalPartitions(log); + } + + public void replayAddExternalPartitions(ExternalObjectLog log) { + LOG.debug("ReplayAddExternalPartitions,catalogId:[{}],dbId:[{}],tableId:[{}]", log.getCatalogId(), + log.getDbId(), log.getTableId()); + ExternalCatalog catalog = (ExternalCatalog) idToCatalog.get(log.getCatalogId()); + ExternalDatabase db = catalog.getDbForReplay(log.getDbId()); + ExternalTable table = db.getTableForReplay(log.getTableId()); + Env.getCurrentEnv().getExtMetaCacheMgr() + .addPartitionsCache(catalog.getId(), table, log.getPartitionNames()); + } + + public void dropExternalPartitions(String catalogName, String dbName, String tableName, List<String> partitionNames) + throws DdlException { + CatalogIf catalog = nameToCatalog.get(catalogName); + if (catalog == null) { + throw new DdlException("No catalog found with name: " + catalogName); + } + if (!(catalog instanceof ExternalCatalog)) { + throw new DdlException("Only support ExternalCatalog"); + } + DatabaseIf db = catalog.getDbNullable(dbName); + if (db == null) { + throw new DdlException("Database " + dbName + " does not exist in catalog " + catalog.getName()); + } + + TableIf table = db.getTableNullable(tableName); + if (table == null) { + throw new DdlException("Table " + tableName + " does not exist in db " + dbName); + } + + ExternalObjectLog log = new ExternalObjectLog(); + log.setCatalogId(catalog.getId()); + log.setDbId(db.getId()); + log.setTableId(table.getId()); + log.setPartitionNames(partitionNames); + replayDropExternalPartitions(log); + Env.getCurrentEnv().getEditLog().logDropExternalPartitions(log); + } + + public void replayDropExternalPartitions(ExternalObjectLog log) { + LOG.debug("ReplayDropExternalPartitions,catalogId:[{}],dbId:[{}],tableId:[{}]", log.getCatalogId(), + log.getDbId(), log.getTableId()); + ExternalCatalog catalog = (ExternalCatalog) idToCatalog.get(log.getCatalogId()); Review Comment: Ditto ########## fe/fe-core/src/main/java/org/apache/doris/datasource/CatalogMgr.java: ########## @@ -583,11 +605,251 @@ public void replayDropExternalTable(ExternalObjectLog log) { ExternalCatalog catalog = (ExternalCatalog) idToCatalog.get(log.getCatalogId()); ExternalDatabase db = catalog.getDbForReplay(log.getDbId()); ExternalTable table = db.getTableForReplay(log.getTableId()); - db.dropTable(table.getName()); + db.writeLock(); + try { + db.dropTable(table.getName()); + } finally { + db.writeUnlock(); + } + Env.getCurrentEnv().getExtMetaCacheMgr() .invalidateTableCache(catalog.getId(), db.getFullName(), table.getName()); } + public boolean externalTableExistInLocal(String dbName, String tableName, String catalogName) throws DdlException { + CatalogIf catalog = nameToCatalog.get(catalogName); + if (catalog == null) { + throw new DdlException("No catalog found with name: " + catalogName); + } + if (!(catalog instanceof ExternalCatalog)) { + throw new DdlException("Only support ExternalCatalog Tables"); + } + return ((ExternalCatalog) catalog).tableExistInLocal(dbName, tableName); + } + + public void createExternalTable(String dbName, String tableName, String catalogName) throws DdlException { + CatalogIf catalog = nameToCatalog.get(catalogName); + if (catalog == null) { + throw new DdlException("No catalog found with name: " + catalogName); + } + if (!(catalog instanceof ExternalCatalog)) { + throw new DdlException("Only support create ExternalCatalog Tables"); + } + DatabaseIf db = catalog.getDbNullable(dbName); + if (db == null) { + throw new DdlException("Database " + dbName + " does not exist in catalog " + catalog.getName()); + } + + TableIf table = db.getTableNullable(tableName); + if (table != null) { + throw new DdlException("Table " + tableName + " has exist in db " + dbName); + } + ExternalObjectLog log = new ExternalObjectLog(); + log.setCatalogId(catalog.getId()); + log.setDbId(db.getId()); + log.setTableName(tableName); + log.setTableId(Env.getCurrentEnv().getNextId()); + replayCreateExternalTable(log); + Env.getCurrentEnv().getEditLog().logCreateExternalTable(log); + } + + public void replayCreateExternalTable(ExternalObjectLog log) { + LOG.debug("ReplayCreateExternalTable,catalogId:[{}],dbId:[{}],tableId:[{}],tableName:[{}]", log.getCatalogId(), + log.getDbId(), log.getTableId(), log.getTableName()); + ExternalCatalog catalog = (ExternalCatalog) idToCatalog.get(log.getCatalogId()); + ExternalDatabase db = catalog.getDbForReplay(log.getDbId()); + db.writeLock(); + try { + db.createTable(log.getTableName(), log.getTableId()); + } finally { + db.writeUnlock(); + } + } + + public void dropExternalDatabase(String dbName, String catalogName) throws DdlException { + CatalogIf catalog = nameToCatalog.get(catalogName); + if (catalog == null) { + throw new DdlException("No catalog found with name: " + catalogName); + } + if (!(catalog instanceof ExternalCatalog)) { + throw new DdlException("Only support drop ExternalCatalog databases"); + } + DatabaseIf db = catalog.getDbNullable(dbName); + if (db == null) { + throw new DdlException("Database " + dbName + " does not exist in catalog " + catalog.getName()); + } + + ExternalObjectLog log = new ExternalObjectLog(); + log.setCatalogId(catalog.getId()); + log.setDbId(db.getId()); + log.setInvalidCache(true); + replayDropExternalDatabase(log); + Env.getCurrentEnv().getEditLog().logDropExternalDatabase(log); + } + + public void replayDropExternalDatabase(ExternalObjectLog log) { + writeLock(); + try { + LOG.debug("ReplayDropExternalTable,catalogId:[{}],dbId:[{}],tableId:[{}]", log.getCatalogId(), + log.getDbId(), log.getTableId()); + ExternalCatalog catalog = (ExternalCatalog) idToCatalog.get(log.getCatalogId()); + ExternalDatabase db = catalog.getDbForReplay(log.getDbId()); + catalog.dropDatabase(db.getFullName()); + Env.getCurrentEnv().getExtMetaCacheMgr().invalidateDbCache(catalog.getId(), db.getFullName()); + } finally { + writeUnlock(); + } + } + + public void createExternalDatabase(String dbName, String catalogName) throws DdlException { + CatalogIf catalog = nameToCatalog.get(catalogName); + if (catalog == null) { + throw new DdlException("No catalog found with name: " + catalogName); + } + if (!(catalog instanceof ExternalCatalog)) { + throw new DdlException("Only support create ExternalCatalog databases"); + } + DatabaseIf db = catalog.getDbNullable(dbName); + if (db != null) { + throw new DdlException("Database " + dbName + " has exist in catalog " + catalog.getName()); + } + + ExternalObjectLog log = new ExternalObjectLog(); + log.setCatalogId(catalog.getId()); + log.setDbId(Env.getCurrentEnv().getNextId()); + log.setDbName(dbName); + replayCreateExternalDatabase(log); + Env.getCurrentEnv().getEditLog().logCreateExternalDatabase(log); + } + + public void replayCreateExternalDatabase(ExternalObjectLog log) { + writeLock(); + try { + LOG.debug("ReplayCreateExternalDatabase,catalogId:[{}],dbId:[{}],dbName:[{}]", log.getCatalogId(), + log.getDbId(), log.getDbName()); + ExternalCatalog catalog = (ExternalCatalog) idToCatalog.get(log.getCatalogId()); + catalog.createDatabase(log.getDbId(), log.getDbName()); + } finally { + writeUnlock(); + } + } + + public void addExternalPartitions(String catalogName, String dbName, String tableName, List<String> partitionNames) + throws DdlException { + CatalogIf catalog = nameToCatalog.get(catalogName); + if (catalog == null) { + throw new DdlException("No catalog found with name: " + catalogName); + } + if (!(catalog instanceof ExternalCatalog)) { + throw new DdlException("Only support ExternalCatalog"); + } + DatabaseIf db = catalog.getDbNullable(dbName); + if (db == null) { + throw new DdlException("Database " + dbName + " does not exist in catalog " + catalog.getName()); + } + + TableIf table = db.getTableNullable(tableName); + if (table == null) { + throw new DdlException("Table " + tableName + " does not exist in db " + dbName); + } + + ExternalObjectLog log = new ExternalObjectLog(); + log.setCatalogId(catalog.getId()); + log.setDbId(db.getId()); + log.setTableId(table.getId()); + log.setPartitionNames(partitionNames); + replayAddExternalPartitions(log); + Env.getCurrentEnv().getEditLog().logAddExternalPartitions(log); + } + + public void replayAddExternalPartitions(ExternalObjectLog log) { + LOG.debug("ReplayAddExternalPartitions,catalogId:[{}],dbId:[{}],tableId:[{}]", log.getCatalogId(), + log.getDbId(), log.getTableId()); + ExternalCatalog catalog = (ExternalCatalog) idToCatalog.get(log.getCatalogId()); Review Comment: Ditto ########## fe/fe-core/src/main/java/org/apache/doris/datasource/CatalogMgr.java: ########## @@ -583,11 +605,251 @@ public void replayDropExternalTable(ExternalObjectLog log) { ExternalCatalog catalog = (ExternalCatalog) idToCatalog.get(log.getCatalogId()); ExternalDatabase db = catalog.getDbForReplay(log.getDbId()); ExternalTable table = db.getTableForReplay(log.getTableId()); - db.dropTable(table.getName()); + db.writeLock(); + try { + db.dropTable(table.getName()); + } finally { + db.writeUnlock(); + } + Env.getCurrentEnv().getExtMetaCacheMgr() .invalidateTableCache(catalog.getId(), db.getFullName(), table.getName()); } + public boolean externalTableExistInLocal(String dbName, String tableName, String catalogName) throws DdlException { + CatalogIf catalog = nameToCatalog.get(catalogName); + if (catalog == null) { + throw new DdlException("No catalog found with name: " + catalogName); + } + if (!(catalog instanceof ExternalCatalog)) { + throw new DdlException("Only support ExternalCatalog Tables"); + } + return ((ExternalCatalog) catalog).tableExistInLocal(dbName, tableName); + } + + public void createExternalTable(String dbName, String tableName, String catalogName) throws DdlException { + CatalogIf catalog = nameToCatalog.get(catalogName); + if (catalog == null) { + throw new DdlException("No catalog found with name: " + catalogName); + } + if (!(catalog instanceof ExternalCatalog)) { + throw new DdlException("Only support create ExternalCatalog Tables"); + } + DatabaseIf db = catalog.getDbNullable(dbName); + if (db == null) { + throw new DdlException("Database " + dbName + " does not exist in catalog " + catalog.getName()); + } + + TableIf table = db.getTableNullable(tableName); + if (table != null) { + throw new DdlException("Table " + tableName + " has exist in db " + dbName); + } + ExternalObjectLog log = new ExternalObjectLog(); + log.setCatalogId(catalog.getId()); + log.setDbId(db.getId()); + log.setTableName(tableName); + log.setTableId(Env.getCurrentEnv().getNextId()); + replayCreateExternalTable(log); + Env.getCurrentEnv().getEditLog().logCreateExternalTable(log); + } + + public void replayCreateExternalTable(ExternalObjectLog log) { + LOG.debug("ReplayCreateExternalTable,catalogId:[{}],dbId:[{}],tableId:[{}],tableName:[{}]", log.getCatalogId(), + log.getDbId(), log.getTableId(), log.getTableName()); + ExternalCatalog catalog = (ExternalCatalog) idToCatalog.get(log.getCatalogId()); + ExternalDatabase db = catalog.getDbForReplay(log.getDbId()); + db.writeLock(); + try { + db.createTable(log.getTableName(), log.getTableId()); + } finally { + db.writeUnlock(); + } + } + + public void dropExternalDatabase(String dbName, String catalogName) throws DdlException { + CatalogIf catalog = nameToCatalog.get(catalogName); + if (catalog == null) { + throw new DdlException("No catalog found with name: " + catalogName); + } + if (!(catalog instanceof ExternalCatalog)) { + throw new DdlException("Only support drop ExternalCatalog databases"); + } + DatabaseIf db = catalog.getDbNullable(dbName); + if (db == null) { + throw new DdlException("Database " + dbName + " does not exist in catalog " + catalog.getName()); + } + + ExternalObjectLog log = new ExternalObjectLog(); + log.setCatalogId(catalog.getId()); + log.setDbId(db.getId()); + log.setInvalidCache(true); + replayDropExternalDatabase(log); + Env.getCurrentEnv().getEditLog().logDropExternalDatabase(log); + } + + public void replayDropExternalDatabase(ExternalObjectLog log) { + writeLock(); + try { + LOG.debug("ReplayDropExternalTable,catalogId:[{}],dbId:[{}],tableId:[{}]", log.getCatalogId(), + log.getDbId(), log.getTableId()); + ExternalCatalog catalog = (ExternalCatalog) idToCatalog.get(log.getCatalogId()); Review Comment: Ditto ########## fe/fe-core/src/main/java/org/apache/doris/datasource/hive/event/AlterDatabaseEvent.java: ########## @@ -0,0 +1,48 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + + +package org.apache.doris.datasource.hive.event; + +import com.google.common.base.Preconditions; +import com.google.common.collect.Lists; +import org.apache.hadoop.hive.metastore.api.NotificationEvent; + +import java.util.List; + +/** + * MetastoreEvent for Alter_DATABASE event type + */ +public class AlterDatabaseEvent extends MetastoreEvent { + + private AlterDatabaseEvent(NotificationEvent event, + String catalogName) { + super(event, catalogName); + Preconditions.checkArgument(getEventType().equals(MetastoreEventType.ALTER_DATABASE)); + } + + protected static List<MetastoreEvent> getEvents(NotificationEvent event, + String catalogName) { + return Lists.newArrayList(new AlterDatabaseEvent(event, catalogName)); + } + + @Override + protected void process() throws MetastoreNotificationException { + // only can change properties,we do nothing + infoLog("catalogName:[{}],dbName:[{}]", catalogName, dbName); Review Comment: You can print the modified properties in this log. so we can get more info. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org