World's most powerful open data catalog for building a high-performance, geo-distributed and federated metadata lake.
Java ai-catalogdata-catalogdatalakefederated-querylakehousemetadatametalakemodel-catalogopendatacatalogskycomputingstratosphere
[#2647] improvement(server): use read lock in list api (#2732)
bknbkn6bc084ef491e
diff --git a/server/src/main/java/com/datastrato/gravitino/server/web/rest/CatalogOperations.java b/server/src/main/java/com/datastrato/gravitino/server/web/rest/CatalogOperations.javaindex 8795192bc9..cefbca7b60 100644--- a/server/src/main/java/com/datastrato/gravitino/server/web/rest/CatalogOperations.java+++ b/server/src/main/java/com/datastrato/gravitino/server/web/rest/CatalogOperations.java@@ -67,7 +67,7 @@ public class CatalogOperations {// Lock the root and the metalake with WRITE lock to ensure the consistency of the list.return TreeLockUtils.doWithTreeLock(NameIdentifier.of(metalake),- LockType.WRITE,+ LockType.READ,() -> {if (verbose) {Catalog[] catalogs = manager.listCatalogsInfo(catalogNS);@@ -95,7 +95,7 @@ public class CatalogOperations {NameIdentifier ident = NameIdentifier.ofCatalog(metalake, request.getName());Catalog catalog =TreeLockUtils.doWithTreeLock(- ident,+ NameIdentifier.ofMetalake(metalake),LockType.WRITE,() ->manager.createCatalog(@@ -149,7 +149,9 @@ public class CatalogOperations {.toArray(CatalogChange[]::new);Catalog catalog =TreeLockUtils.doWithTreeLock(- ident, LockType.WRITE, () -> manager.alterCatalog(ident, changes));+ NameIdentifier.ofMetalake(metalakeName),+ LockType.WRITE,+ () -> manager.alterCatalog(ident, changes));return Utils.ok(new CatalogResponse(DTOConverters.toDTO(catalog)));});@@ -171,7 +173,9 @@ public class CatalogOperations {NameIdentifier ident = NameIdentifier.ofCatalog(metalakeName, catalogName);boolean dropped =TreeLockUtils.doWithTreeLock(- ident, LockType.WRITE, () -> manager.dropCatalog(ident));+ NameIdentifier.ofMetalake(metalakeName),+ LockType.WRITE,+ () -> manager.dropCatalog(ident));if (!dropped) {LOG.warn("Failed to drop catalog {} under metalake {}", catalogName, metalakeName);}diff --git a/server/src/main/java/com/datastrato/gravitino/server/web/rest/FilesetOperations.java b/server/src/main/java/com/datastrato/gravitino/server/web/rest/FilesetOperations.javaindex 1e24834e48..49f245b072 100644--- a/server/src/main/java/com/datastrato/gravitino/server/web/rest/FilesetOperations.java+++ b/server/src/main/java/com/datastrato/gravitino/server/web/rest/FilesetOperations.java@@ -67,7 +67,7 @@ public class FilesetOperations {NameIdentifier[] idents =TreeLockUtils.doWithTreeLock(NameIdentifier.of(metalake, catalog, schema),- LockType.WRITE,+ LockType.READ,() -> dispatcher.listFilesets(filesetNS));return Utils.ok(new EntityListResponse(idents));});@@ -96,7 +96,7 @@ public class FilesetOperations {Fileset fileset =TreeLockUtils.doWithTreeLock(- ident,+ NameIdentifier.ofSchema(metalake, catalog, schema),LockType.WRITE,() ->dispatcher.createFileset(@@ -162,7 +162,9 @@ public class FilesetOperations {.toArray(FilesetChange[]::new);Fileset t =TreeLockUtils.doWithTreeLock(- ident, LockType.WRITE, () -> dispatcher.alterFileset(ident, changes));+ NameIdentifier.ofSchema(metalake, catalog, schema),+ LockType.WRITE,+ () -> dispatcher.alterFileset(ident, changes));return Utils.ok(new FilesetResponse(DTOConverters.toDTO(t)));});@@ -188,7 +190,9 @@ public class FilesetOperations {NameIdentifier ident = NameIdentifier.ofFileset(metalake, catalog, schema, fileset);boolean dropped =TreeLockUtils.doWithTreeLock(- ident, LockType.WRITE, () -> dispatcher.dropFileset(ident));+ NameIdentifier.ofSchema(metalake, catalog, schema),+ LockType.WRITE,+ () -> dispatcher.dropFileset(ident));if (!dropped) {LOG.warn("Failed to drop fileset {} under schema {}", fileset, schema);}diff --git a/server/src/main/java/com/datastrato/gravitino/server/web/rest/MetalakeOperations.java b/server/src/main/java/com/datastrato/gravitino/server/web/rest/MetalakeOperations.javaindex 76a3204936..c0a91613fa 100644--- a/server/src/main/java/com/datastrato/gravitino/server/web/rest/MetalakeOperations.java+++ b/server/src/main/java/com/datastrato/gravitino/server/web/rest/MetalakeOperations.java@@ -66,7 +66,7 @@ public class MetalakeOperations {httpRequest,() -> {BaseMetalake[] metalakes =- TreeLockUtils.doWithRootTreeLock(LockType.WRITE, manager::listMetalakes);+ TreeLockUtils.doWithRootTreeLock(LockType.READ, manager::listMetalakes);MetalakeDTO[] metalakeDTOS =Arrays.stream(metalakes).map(DTOConverters::toDTO).toArray(MetalakeDTO[]::new);return Utils.ok(new MetalakeListResponse(metalakeDTOS));@@ -90,8 +90,7 @@ public class MetalakeOperations {request.validate();NameIdentifier ident = NameIdentifier.ofMetalake(request.getName());BaseMetalake metalake =- TreeLockUtils.doWithTreeLock(- ident,+ TreeLockUtils.doWithRootTreeLock(LockType.WRITE,() ->manager.createMetalake(@@ -144,8 +143,8 @@ public class MetalakeOperations {.map(MetalakeUpdateRequest::metalakeChange).toArray(MetalakeChange[]::new);BaseMetalake updatedMetalake =- TreeLockUtils.doWithTreeLock(- identifier, LockType.WRITE, () -> manager.alterMetalake(identifier, changes));+ TreeLockUtils.doWithRootTreeLock(+ LockType.WRITE, () -> manager.alterMetalake(identifier, changes));return Utils.ok(new MetalakeResponse(DTOConverters.toDTO(updatedMetalake)));});@@ -166,8 +165,8 @@ public class MetalakeOperations {() -> {NameIdentifier identifier = NameIdentifier.ofMetalake(metalakeName);boolean dropped =- TreeLockUtils.doWithTreeLock(- identifier, LockType.WRITE, () -> manager.dropMetalake(identifier));+ TreeLockUtils.doWithRootTreeLock(+ LockType.WRITE, () -> manager.dropMetalake(identifier));if (!dropped) {LOG.warn("Failed to drop metalake by name {}", metalakeName);}diff --git a/server/src/main/java/com/datastrato/gravitino/server/web/rest/SchemaOperations.java b/server/src/main/java/com/datastrato/gravitino/server/web/rest/SchemaOperations.javaindex bc4dcc009d..00b4ff6b13 100644--- a/server/src/main/java/com/datastrato/gravitino/server/web/rest/SchemaOperations.java+++ b/server/src/main/java/com/datastrato/gravitino/server/web/rest/SchemaOperations.java@@ -70,7 +70,7 @@ public class SchemaOperations {NameIdentifier[] idents =TreeLockUtils.doWithTreeLock(NameIdentifier.of(metalake, catalog),- LockType.WRITE,+ LockType.READ,() -> dispatcher.listSchemas(schemaNS));return Utils.ok(new EntityListResponse(idents));});@@ -95,7 +95,7 @@ public class SchemaOperations {NameIdentifier ident = NameIdentifier.ofSchema(metalake, catalog, request.getName());Schema schema =TreeLockUtils.doWithTreeLock(- ident,+ NameIdentifier.ofCatalog(metalake, catalog),LockType.WRITE,() ->dispatcher.createSchema(@@ -156,7 +156,9 @@ public class SchemaOperations {.toArray(SchemaChange[]::new);Schema s =TreeLockUtils.doWithTreeLock(- ident, LockType.WRITE, () -> dispatcher.alterSchema(ident, changes));+ NameIdentifier.ofCatalog(metalake, catalog),+ LockType.WRITE,+ () -> dispatcher.alterSchema(ident, changes));return Utils.ok(new SchemaResponse(DTOConverters.toDTO(s)));});@@ -182,7 +184,9 @@ public class SchemaOperations {NameIdentifier ident = NameIdentifier.ofSchema(metalake, catalog, schema);boolean dropped =TreeLockUtils.doWithTreeLock(- ident, LockType.WRITE, () -> dispatcher.dropSchema(ident, cascade));+ NameIdentifier.ofCatalog(metalake, catalog),+ LockType.WRITE,+ () -> dispatcher.dropSchema(ident, cascade));if (!dropped) {LOG.warn("Fail to drop schema {} under namespace {}", schema, ident.namespace());}diff --git a/server/src/main/java/com/datastrato/gravitino/server/web/rest/TableOperations.java b/server/src/main/java/com/datastrato/gravitino/server/web/rest/TableOperations.javaindex e499270087..2c94c7caa8 100644--- a/server/src/main/java/com/datastrato/gravitino/server/web/rest/TableOperations.java+++ b/server/src/main/java/com/datastrato/gravitino/server/web/rest/TableOperations.java@@ -71,7 +71,7 @@ public class TableOperations {NameIdentifier[] idents =TreeLockUtils.doWithTreeLock(NameIdentifier.of(metalake, catalog, schema),- LockType.WRITE,+ LockType.READ,() -> dispatcher.listTables(tableNS));return Utils.ok(new EntityListResponse(idents));});@@ -100,7 +100,7 @@ public class TableOperations {Table table =TreeLockUtils.doWithTreeLock(- ident,+ NameIdentifier.of(metalake, catalog, schema),LockType.WRITE,() ->dispatcher.createTable(@@ -169,7 +169,9 @@ public class TableOperations {.toArray(TableChange[]::new);Table t =TreeLockUtils.doWithTreeLock(- ident, LockType.WRITE, () -> dispatcher.alterTable(ident, changes));+ NameIdentifier.of(metalake, catalog, schema),+ LockType.WRITE,+ () -> dispatcher.alterTable(ident, changes));return Utils.ok(new TableResponse(DTOConverters.toDTO(t)));});@@ -196,7 +198,7 @@ public class TableOperations {NameIdentifier ident = NameIdentifier.ofTable(metalake, catalog, schema, table);boolean dropped =TreeLockUtils.doWithTreeLock(- ident,+ NameIdentifier.of(metalake, catalog, schema),LockType.WRITE,() -> purge ? dispatcher.purgeTable(ident) : dispatcher.dropTable(ident));if (!dropped) {diff --git a/server/src/main/java/com/datastrato/gravitino/server/web/rest/TopicOperations.java b/server/src/main/java/com/datastrato/gravitino/server/web/rest/TopicOperations.javaindex e09440432b..c0b52751bb 100644--- a/server/src/main/java/com/datastrato/gravitino/server/web/rest/TopicOperations.java+++ b/server/src/main/java/com/datastrato/gravitino/server/web/rest/TopicOperations.java@@ -65,7 +65,7 @@ public class TopicOperations {NameIdentifier[] topics =TreeLockUtils.doWithTreeLock(NameIdentifier.of(metalake, catalog, schema),- LockType.WRITE,+ LockType.READ,() -> dispatcher.listTopics(topicNS));return Utils.ok(new EntityListResponse(topics));});@@ -99,7 +99,7 @@ public class TopicOperations {Topic topic =TreeLockUtils.doWithTreeLock(- ident,+ NameIdentifier.ofSchema(metalake, catalog, schema),LockType.WRITE,() ->dispatcher.createTopic(@@ -166,7 +166,9 @@ public class TopicOperations {Topic t =TreeLockUtils.doWithTreeLock(- ident, LockType.WRITE, () -> dispatcher.alterTopic(ident, changes));+ NameIdentifier.ofSchema(metalake, catalog, schema),+ LockType.WRITE,+ () -> dispatcher.alterTopic(ident, changes));return Utils.ok(new TopicResponse(DTOConverters.toDTO(t)));});} catch (Exception e) {@@ -192,7 +194,9 @@ public class TopicOperations {NameIdentifier ident = NameIdentifier.ofTopic(metalake, catalog, schema, topic);boolean dropped =TreeLockUtils.doWithTreeLock(- ident, LockType.WRITE, () -> dispatcher.dropTopic(ident));+ NameIdentifier.ofSchema(metalake, catalog, schema),+ LockType.WRITE,+ () -> dispatcher.dropTopic(ident));if (!dropped) {LOG.warn("Failed to drop topic {} under schema {}", topic, schema);