Skip to content

Commit 0eec636

Browse files
authored
[#6474] improvement(storage): batch listing securable objects in RoleMetaService (#6601)
<!-- 1. Title: [#<issue>] <type>(<scope>): <subject> Examples: - "[#123] feat(operator): support xxx" - "[#233] fix: check null before access result in xxx" - "[MINOR] refactor: fix typo in variable name" - "[MINOR] docs: fix typo in README" - "[#255] test: fix flaky test NameOfTheTest" Reference: https://www.conventionalcommits.org/en/v1.0.0/ 2. If the PR is unfinished, please mark this PR as draft. --> ### What changes were proposed in this pull request? Batch retrieving securable objects for `metalake`, `catalog`, `schema`, `table`, `topic`, `fileset` (fileset has been implemented at #6455). ### Why are the changes needed? Improve performance when role is bounded to lots of `SecurableObject`s. Fix: #6474 ### Does this PR introduce _any_ user-facing change? No. ### How was this patch tested? In `TestSecurableObjects.testAllTypeSecurableObjects`. Related Issue and PR: #6238 #6455
1 parent c9c9a99 commit 0eec636

16 files changed

+468
-115
lines changed

api/src/main/java/org/apache/gravitino/authorization/SecurableObjects.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ public static SecurableObject ofTopic(
105105
}
106106

107107
/**
108-
* Create the table {@link SecurableObject} with the given securable schema object, fileset name
108+
* Create the fileset {@link SecurableObject} with the given securable schema object, fileset name
109109
* and privileges.
110110
*
111111
* @param schema The schema securable object

core/src/main/java/org/apache/gravitino/storage/relational/mapper/MetalakeMetaMapper.java

+5
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ public interface MetalakeMetaMapper {
4747
@SelectProvider(type = MetalakeMetaSQLProviderFactory.class, method = "selectMetalakeMetaById")
4848
MetalakePO selectMetalakeMetaById(@Param("metalakeId") Long metalakeId);
4949

50+
@SelectProvider(
51+
type = MetalakeMetaSQLProviderFactory.class,
52+
method = "listMetalakePOsByMetalakeIds")
53+
List<MetalakePO> listMetalakePOsByMetalakeIds(@Param("metalakeIds") List<Long> metalakeIds);
54+
5055
@SelectProvider(
5156
type = MetalakeMetaSQLProviderFactory.class,
5257
method = "selectMetalakeIdMetaByName")

core/src/main/java/org/apache/gravitino/storage/relational/mapper/MetalakeMetaSQLProviderFactory.java

+5
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
package org.apache.gravitino.storage.relational.mapper;
2121

2222
import com.google.common.collect.ImmutableMap;
23+
import java.util.List;
2324
import java.util.Map;
2425
import org.apache.gravitino.storage.relational.JDBCBackend.JDBCBackendType;
2526
import org.apache.gravitino.storage.relational.mapper.provider.base.MetalakeMetaBaseSQLProvider;
@@ -68,6 +69,10 @@ public static String selectMetalakeIdMetaByName(@Param("metalakeName") String me
6869
return getProvider().selectMetalakeIdMetaByName(metalakeName);
6970
}
7071

72+
public static String listMetalakePOsByMetalakeIds(@Param("metalakeIds") List<Long> metalakeIds) {
73+
return getProvider().listMetalakePOsByMetalakeIds(metalakeIds);
74+
}
75+
7176
public static String insertMetalakeMeta(@Param("metalakeMeta") MetalakePO metalakePO) {
7277
return getProvider().insertMetalakeMeta(metalakePO);
7378
}

core/src/main/java/org/apache/gravitino/storage/relational/mapper/ModelMetaMapper.java

+3
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ public interface ModelMetaMapper {
4040
@SelectProvider(type = ModelMetaSQLProviderFactory.class, method = "listModelPOsBySchemaId")
4141
List<ModelPO> listModelPOsBySchemaId(@Param("schemaId") Long schemaId);
4242

43+
@SelectProvider(type = ModelMetaSQLProviderFactory.class, method = "listModelPOsByModelIds")
44+
List<ModelPO> listModelPOsByModelIds(@Param("modelIds") List<Long> modelIds);
45+
4346
@SelectProvider(
4447
type = ModelMetaSQLProviderFactory.class,
4548
method = "selectModelMetaBySchemaIdAndModelName")

core/src/main/java/org/apache/gravitino/storage/relational/mapper/ModelMetaSQLProviderFactory.java

+5
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
package org.apache.gravitino.storage.relational.mapper;
2020

2121
import com.google.common.collect.ImmutableMap;
22+
import java.util.List;
2223
import java.util.Map;
2324
import org.apache.gravitino.storage.relational.JDBCBackend.JDBCBackendType;
2425
import org.apache.gravitino.storage.relational.mapper.provider.base.ModelMetaBaseSQLProvider;
@@ -62,6 +63,10 @@ public static String listModelPOsBySchemaId(@Param("schemaId") Long schemaId) {
6263
return getProvider().listModelPOsBySchemaId(schemaId);
6364
}
6465

66+
public static String listModelPOsByModelIds(@Param("modelIds") List<Long> modelIds) {
67+
return getProvider().listModelPOsByModelIds(modelIds);
68+
}
69+
6570
public static String selectModelMetaBySchemaIdAndModelName(
6671
@Param("schemaId") Long schemaId, @Param("modelName") String modelName) {
6772
return getProvider().selectModelMetaBySchemaIdAndModelName(schemaId, modelName);

core/src/main/java/org/apache/gravitino/storage/relational/mapper/TableMetaMapper.java

+3
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ public interface TableMetaMapper {
4141
@SelectProvider(type = TableMetaSQLProviderFactory.class, method = "listTablePOsBySchemaId")
4242
List<TablePO> listTablePOsBySchemaId(@Param("schemaId") Long schemaId);
4343

44+
@SelectProvider(type = TableMetaSQLProviderFactory.class, method = "listTablePOsByTableIds")
45+
List<TablePO> listTablePOsByTableIds(@Param("tableIds") List<Long> tableIds);
46+
4447
@SelectProvider(
4548
type = TableMetaSQLProviderFactory.class,
4649
method = "selectTableIdBySchemaIdAndName")

core/src/main/java/org/apache/gravitino/storage/relational/mapper/TableMetaSQLProviderFactory.java

+5
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
package org.apache.gravitino.storage.relational.mapper;
2020

2121
import com.google.common.collect.ImmutableMap;
22+
import java.util.List;
2223
import java.util.Map;
2324
import org.apache.gravitino.storage.relational.JDBCBackend.JDBCBackendType;
2425
import org.apache.gravitino.storage.relational.mapper.provider.base.TableMetaBaseSQLProvider;
@@ -54,6 +55,10 @@ public static String listTablePOsBySchemaId(@Param("schemaId") Long schemaId) {
5455
return getProvider().listTablePOsBySchemaId(schemaId);
5556
}
5657

58+
public static String listTablePOsByTableIds(@Param("tableIds") List<Long> tableIds) {
59+
return getProvider().listTablePOsByTableIds(tableIds);
60+
}
61+
5762
public static String selectTableIdBySchemaIdAndName(
5863
@Param("schemaId") Long schemaId, @Param("tableName") String name) {
5964
return getProvider().selectTableIdBySchemaIdAndName(schemaId, name);

core/src/main/java/org/apache/gravitino/storage/relational/mapper/TopicMetaMapper.java

+3
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ public interface TopicMetaMapper {
4040
@SelectProvider(type = TopicMetaSQLProviderFactory.class, method = "listTopicPOsBySchemaId")
4141
List<TopicPO> listTopicPOsBySchemaId(@Param("schemaId") Long schemaId);
4242

43+
@SelectProvider(type = TopicMetaSQLProviderFactory.class, method = "listTopicPOsByTopicIds")
44+
List<TopicPO> listTopicPOsByTopicIds(@Param("topicIds") List<Long> topicIds);
45+
4346
@SelectProvider(
4447
type = TopicMetaSQLProviderFactory.class,
4548
method = "selectTopicMetaBySchemaIdAndName")

core/src/main/java/org/apache/gravitino/storage/relational/mapper/TopicMetaSQLProviderFactory.java

+5
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
package org.apache.gravitino.storage.relational.mapper;
2121

2222
import com.google.common.collect.ImmutableMap;
23+
import java.util.List;
2324
import java.util.Map;
2425
import org.apache.gravitino.storage.relational.JDBCBackend.JDBCBackendType;
2526
import org.apache.gravitino.storage.relational.mapper.provider.base.TopicMetaBaseSQLProvider;
@@ -63,6 +64,10 @@ public static String listTopicPOsBySchemaId(@Param("schemaId") Long schemaId) {
6364
return getProvider().listTopicPOsBySchemaId(schemaId);
6465
}
6566

67+
public static String listTopicPOsByTopicIds(@Param("topicIds") List<Long> topicIds) {
68+
return getProvider().listTopicPOsByTopicIds(topicIds);
69+
}
70+
6671
public static String selectTopicMetaBySchemaIdAndName(
6772
@Param("schemaId") Long schemaId, @Param("topicName") String topicName) {
6873
return getProvider().selectTopicMetaBySchemaIdAndName(schemaId, topicName);

core/src/main/java/org/apache/gravitino/storage/relational/mapper/provider/base/MetalakeMetaBaseSQLProvider.java

+19
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
import static org.apache.gravitino.storage.relational.mapper.MetalakeMetaMapper.TABLE_NAME;
2222

23+
import java.util.List;
2324
import org.apache.gravitino.storage.relational.po.MetalakePO;
2425
import org.apache.ibatis.annotations.Param;
2526

@@ -65,6 +66,24 @@ public String selectMetalakeIdMetaByName(@Param("metalakeName") String metalakeN
6566
+ " WHERE metalake_name = #{metalakeName} and deleted_at = 0";
6667
}
6768

69+
public String listMetalakePOsByMetalakeIds(@Param("metalakeIds") List<Long> metalakeIds) {
70+
return "<script>"
71+
+ " SELECT metalake_id as metalakeId, metalake_name as metalakeName,"
72+
+ " metalake_comment as metalakeComment, properties,"
73+
+ " audit_info as auditInfo, schema_version as schemaVersion,"
74+
+ " current_version as currentVersion, last_version as lastVersion,"
75+
+ " deleted_at as deletedAt"
76+
+ " FROM "
77+
+ TABLE_NAME
78+
+ " WHERE deleted_at = 0"
79+
+ " AND metalake_id in ("
80+
+ "<foreach collection='metalakeIds' item='metalakeId' separator=','>"
81+
+ "#{metalakeId}"
82+
+ "</foreach>"
83+
+ ") "
84+
+ "</script>";
85+
}
86+
6887
public String insertMetalakeMeta(@Param("metalakeMeta") MetalakePO metalakePO) {
6988
return "INSERT INTO "
7089
+ TABLE_NAME

core/src/main/java/org/apache/gravitino/storage/relational/mapper/provider/base/ModelMetaBaseSQLProvider.java

+18
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
*/
1919
package org.apache.gravitino.storage.relational.mapper.provider.base;
2020

21+
import java.util.List;
2122
import org.apache.gravitino.storage.relational.mapper.ModelMetaMapper;
2223
import org.apache.gravitino.storage.relational.po.ModelPO;
2324
import org.apache.ibatis.annotations.Param;
@@ -66,6 +67,23 @@ public String listModelPOsBySchemaId(@Param("schemaId") Long schemaId) {
6667
+ " WHERE schema_id = #{schemaId} AND deleted_at = 0";
6768
}
6869

70+
public String listModelPOsByModelIds(List<Long> modelIds) {
71+
return "<script>"
72+
+ " SELECT model_id AS modelId, model_name AS modelName, metalake_id AS metalakeId,"
73+
+ " catalog_id AS catalogId, schema_id AS schemaId, model_comment AS modelComment,"
74+
+ " model_properties AS modelProperties, model_latest_version AS"
75+
+ " modelLatestVersion, audit_info AS auditInfo, deleted_at AS deletedAt"
76+
+ " FROM "
77+
+ ModelMetaMapper.TABLE_NAME
78+
+ " WHERE deleted_at = 0"
79+
+ " AND model_id in ("
80+
+ "<foreach collection='modelIds' item='modelId' separator=','>"
81+
+ "#{modelId}"
82+
+ "</foreach>"
83+
+ ") "
84+
+ "</script>";
85+
}
86+
6987
public String selectModelMetaBySchemaIdAndModelName(
7088
@Param("schemaId") Long schemaId, @Param("modelName") String modelName) {
7189
return "SELECT model_id AS modelId, model_name AS modelName, metalake_id AS metalakeId,"

core/src/main/java/org/apache/gravitino/storage/relational/mapper/provider/base/TableMetaBaseSQLProvider.java

+19
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
import static org.apache.gravitino.storage.relational.mapper.TableMetaMapper.TABLE_NAME;
2222

23+
import java.util.List;
2324
import org.apache.gravitino.storage.relational.po.TablePO;
2425
import org.apache.ibatis.annotations.Param;
2526

@@ -36,6 +37,24 @@ public String listTablePOsBySchemaId(@Param("schemaId") Long schemaId) {
3637
+ " WHERE schema_id = #{schemaId} AND deleted_at = 0";
3738
}
3839

40+
public String listTablePOsByTableIds(List<Long> tableIds) {
41+
return "<script>"
42+
+ " SELECT table_id as tableId, table_name as tableName,"
43+
+ " metalake_id as metalakeId, catalog_id as catalogId,"
44+
+ " schema_id as schemaId, audit_info as auditInfo,"
45+
+ " current_version as currentVersion, last_version as lastVersion,"
46+
+ " deleted_at as deletedAt"
47+
+ " FROM "
48+
+ TABLE_NAME
49+
+ " WHERE deleted_at = 0"
50+
+ " AND table_id in ("
51+
+ "<foreach collection='tableIds' item='tableId' separator=','>"
52+
+ "#{tableId}"
53+
+ "</foreach>"
54+
+ ") "
55+
+ "</script>";
56+
}
57+
3958
public String selectTableIdBySchemaIdAndName(
4059
@Param("schemaId") Long schemaId, @Param("tableName") String name) {
4160
return "SELECT table_id as tableId FROM "

core/src/main/java/org/apache/gravitino/storage/relational/mapper/provider/base/TopicMetaBaseSQLProvider.java

+19
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
import static org.apache.gravitino.storage.relational.mapper.TopicMetaMapper.TABLE_NAME;
2323

24+
import java.util.List;
2425
import org.apache.gravitino.storage.relational.po.TopicPO;
2526
import org.apache.ibatis.annotations.Param;
2627

@@ -90,6 +91,24 @@ public String listTopicPOsBySchemaId(@Param("schemaId") Long schemaId) {
9091
+ " WHERE schema_id = #{schemaId} AND deleted_at = 0";
9192
}
9293

94+
public String listTopicPOsByTopicIds(@Param("topicIds") List<Long> topicIds) {
95+
return "<script>"
96+
+ " SELECT topic_id as topicId, topic_name as topicName, metalake_id as metalakeId,"
97+
+ " catalog_id as catalogId, schema_id as schemaId,"
98+
+ " comment as comment, properties as properties, audit_info as auditInfo,"
99+
+ " current_version as currentVersion, last_version as lastVersion,"
100+
+ " deleted_at as deletedAt"
101+
+ " FROM "
102+
+ TABLE_NAME
103+
+ " WHERE deleted_at = 0"
104+
+ " AND topic_id in ("
105+
+ "<foreach collection='topicIds' item='topicId' separator=','>"
106+
+ "#{topicId}"
107+
+ "</foreach>"
108+
+ ") "
109+
+ "</script>";
110+
}
111+
93112
public String selectTopicMetaBySchemaIdAndName(
94113
@Param("schemaId") Long schemaId, @Param("topicName") String topicName) {
95114
return "SELECT topic_id as topicId, topic_name as topicName,"

0 commit comments

Comments
 (0)