Skip to content

World's most powerful open data catalog for building a high-performance, geo-distributed and federated metadata lake.

[#6852] improvement(core): Optimize SchemaOperationDispatcher to get entity id when loading schema (#6853)

Mini Yuff32ceff22df
diff --git a/core/src/main/java/org/apache/gravitino/catalog/EntityCombinedFileset.java b/core/src/main/java/org/apache/gravitino/catalog/EntityCombinedFileset.java
index 9b7fc8bd35..d9521ee0b6 100644
--- a/core/src/main/java/org/apache/gravitino/catalog/EntityCombinedFileset.java
+++ b/core/src/main/java/org/apache/gravitino/catalog/EntityCombinedFileset.java
@@ -40,6 +40,14 @@ public final class EntityCombinedFileset implements Fileset {
this.filesetEntity = filesetEntity;
}
+ public FilesetEntity filesetEntity() {
+ return filesetEntity;
+ }
+
+ public Fileset fileset() {
+ return fileset;
+ }
+
public static EntityCombinedFileset of(Fileset fileset, FilesetEntity filesetEntity) {
return new EntityCombinedFileset(fileset, filesetEntity);
}
diff --git a/core/src/main/java/org/apache/gravitino/catalog/EntityCombinedModel.java b/core/src/main/java/org/apache/gravitino/catalog/EntityCombinedModel.java
index 740a5dbd5e..ef4f9df3fa 100644
--- a/core/src/main/java/org/apache/gravitino/catalog/EntityCombinedModel.java
+++ b/core/src/main/java/org/apache/gravitino/catalog/EntityCombinedModel.java
@@ -40,6 +40,14 @@ public final class EntityCombinedModel implements Model {
this.modelEntity = modelEntity;
}
+ public ModelEntity modelEntity() {
+ return modelEntity;
+ }
+
+ public Model model() {
+ return model;
+ }
+
public static EntityCombinedModel of(Model model, ModelEntity modelEntity) {
return new EntityCombinedModel(model, modelEntity);
}
diff --git a/core/src/main/java/org/apache/gravitino/catalog/EntityCombinedSchema.java b/core/src/main/java/org/apache/gravitino/catalog/EntityCombinedSchema.java
index a9cd7cfe8a..97f20b4cf6 100644
--- a/core/src/main/java/org/apache/gravitino/catalog/EntityCombinedSchema.java
+++ b/core/src/main/java/org/apache/gravitino/catalog/EntityCombinedSchema.java
@@ -53,6 +53,14 @@ public final class EntityCombinedSchema implements Schema {
this.imported = false;
}
+ public SchemaEntity schemaEntity() {
+ return schemaEntity;
+ }
+
+ public Schema schema() {
+ return schema;
+ }
+
public static EntityCombinedSchema of(Schema schema, SchemaEntity schemaEntity) {
return new EntityCombinedSchema(schema, schemaEntity);
}
diff --git a/core/src/main/java/org/apache/gravitino/catalog/EntityCombinedTable.java b/core/src/main/java/org/apache/gravitino/catalog/EntityCombinedTable.java
index a70699ac7f..921b14dcdf 100644
--- a/core/src/main/java/org/apache/gravitino/catalog/EntityCombinedTable.java
+++ b/core/src/main/java/org/apache/gravitino/catalog/EntityCombinedTable.java
@@ -59,6 +59,10 @@ public final class EntityCombinedTable implements Table {
this.imported = false;
}
+ public TableEntity tableEntity() {
+ return tableEntity;
+ }
+
public static EntityCombinedTable of(Table table, TableEntity tableEntity) {
return new EntityCombinedTable(table, tableEntity);
}
diff --git a/core/src/main/java/org/apache/gravitino/catalog/EntityCombinedTopic.java b/core/src/main/java/org/apache/gravitino/catalog/EntityCombinedTopic.java
index 6193fadacf..210763821c 100644
--- a/core/src/main/java/org/apache/gravitino/catalog/EntityCombinedTopic.java
+++ b/core/src/main/java/org/apache/gravitino/catalog/EntityCombinedTopic.java
@@ -52,6 +52,14 @@ public class EntityCombinedTopic implements Topic {
this.imported = false;
}
+ public TopicEntity topicEntity() {
+ return topicEntity;
+ }
+
+ public Topic topic() {
+ return topic;
+ }
+
public static EntityCombinedTopic of(Topic topic, TopicEntity topicEntity) {
return new EntityCombinedTopic(topic, topicEntity);
}
diff --git a/core/src/main/java/org/apache/gravitino/catalog/OperationDispatcher.java b/core/src/main/java/org/apache/gravitino/catalog/OperationDispatcher.java
index 87daa584f8..887468edc7 100644
--- a/core/src/main/java/org/apache/gravitino/catalog/OperationDispatcher.java
+++ b/core/src/main/java/org/apache/gravitino/catalog/OperationDispatcher.java
@@ -233,22 +233,13 @@ public abstract class OperationDispatcher {
IllegalArgumentException.class);
}
- protected boolean isEntityExist(NameIdentifier ident, Entity.EntityType type) {
- try {
- return store.exists(ident, type);
- } catch (Exception e) {
- LOG.error(FormattedErrorMessages.STORE_OP_FAILURE, "exists", ident, e);
- throw new RuntimeException("Fail to check if entity is existed", e);
- }
- }
-
protected <E extends Entity & HasIdentifier> E getEntity(
NameIdentifier ident, Entity.EntityType type, Class<E> entityClass) {
try {
return store.get(ident, type, entityClass);
} catch (Exception e) {
- LOG.error(FormattedErrorMessages.STORE_OP_FAILURE, "get", ident, e);
- throw new RuntimeException("Fail to check if entity is existed", e);
+ LOG.warn(FormattedErrorMessages.STORE_OP_FAILURE, "get", ident, e.getMessage(), e);
+ return null;
}
}
diff --git a/core/src/main/java/org/apache/gravitino/catalog/SchemaOperationDispatcher.java b/core/src/main/java/org/apache/gravitino/catalog/SchemaOperationDispatcher.java
index b898192c00..a388fff252 100644
--- a/core/src/main/java/org/apache/gravitino/catalog/SchemaOperationDispatcher.java
+++ b/core/src/main/java/org/apache/gravitino/catalog/SchemaOperationDispatcher.java
@@ -241,20 +241,24 @@ public class SchemaOperationDispatcher extends OperationDispatcher implements Sc
StringIdentifier stringId = getStringIdFromProperties(alteredSchema.properties());
// Case 1: The schema is not created by Gravitino and this schema is never imported.
- if (stringId == null && !isEntityExist(ident, SCHEMA)) {
- return EntityCombinedSchema.of(alteredSchema)
- .withHiddenProperties(
- getHiddenPropertyNames(
- catalogIdent,
- HasPropertyMetadata::schemaPropertiesMetadata,
- alteredSchema.properties()));
+ SchemaEntity se = null;
+ if (stringId == null) {
+ se = getEntity(ident, SCHEMA, SchemaEntity.class);
+ if (se == null) {
+ return EntityCombinedSchema.of(alteredSchema)
+ .withHiddenProperties(
+ getHiddenPropertyNames(
+ catalogIdent,
+ HasPropertyMetadata::schemaPropertiesMetadata,
+ alteredSchema.properties()));
+ }
}
long schemaId;
if (stringId != null) {
schemaId = stringId.id();
} else {
- schemaId = getEntity(ident, SCHEMA, SchemaEntity.class).id();
+ schemaId = se.id();
}
SchemaEntity updatedSchemaEntity =
@@ -418,7 +422,18 @@ public class SchemaOperationDispatcher extends OperationDispatcher implements Sc
// Case 1: The schema is not created by Gravitino or the external system does not support
// storing string identifiers.
if (stringId == null) {
- return EntityCombinedSchema.of(schema)
+ SchemaEntity schemaEntity = getEntity(ident, SCHEMA, SchemaEntity.class);
+ if (schemaEntity == null) {
+ return EntityCombinedSchema.of(schema)
+ .withHiddenProperties(
+ getHiddenPropertyNames(
+ catalogIdentifier,
+ HasPropertyMetadata::schemaPropertiesMetadata,
+ schema.properties()))
+ .withImported(false);
+ }
+
+ return EntityCombinedSchema.of(schema, schemaEntity)
.withHiddenProperties(
getHiddenPropertyNames(
catalogIdentifier,
@@ -427,7 +442,7 @@ public class SchemaOperationDispatcher extends OperationDispatcher implements Sc
// For some catalogs like PG, the identifier information is not stored in the schema's
// metadata, we need to check if this schema is existed in the store, if so we don't
// need to import.
- .withImported(isEntityExist(ident, SCHEMA));
+ .withImported(true);
}
SchemaEntity schemaEntity =
diff --git a/core/src/main/java/org/apache/gravitino/catalog/TableOperationDispatcher.java b/core/src/main/java/org/apache/gravitino/catalog/TableOperationDispatcher.java
index 312184e2b4..f110dc02bb 100644
--- a/core/src/main/java/org/apache/gravitino/catalog/TableOperationDispatcher.java
+++ b/core/src/main/java/org/apache/gravitino/catalog/TableOperationDispatcher.java
@@ -222,20 +222,24 @@ public class TableOperationDispatcher extends OperationDispatcher implements Tab
StringIdentifier stringId = getStringIdFromProperties(alteredTable.properties());
// Case 1: The table is not created by Gravitino and this table is never imported.
- if (stringId == null && !isEntityExist(ident, TABLE)) {
- return EntityCombinedTable.of(alteredTable)
- .withHiddenProperties(
- getHiddenPropertyNames(
- getCatalogIdentifier(ident),
- HasPropertyMetadata::tablePropertiesMetadata,
- alteredTable.properties()));
+ TableEntity te = null;
+ if (stringId == null) {
+ te = getEntity(ident, TABLE, TableEntity.class);
+ if (te == null) {
+ return EntityCombinedTable.of(alteredTable)
+ .withHiddenProperties(
+ getHiddenPropertyNames(
+ getCatalogIdentifier(ident),
+ HasPropertyMetadata::tablePropertiesMetadata,
+ alteredTable.properties()));
+ }
}
long tableId;
if (stringId != null) {
tableId = stringId.id();
} else {
- tableId = getEntity(ident, TABLE, TableEntity.class).id();
+ tableId = te.id();
}
TableEntity updatedTableEntity =
@@ -464,7 +468,21 @@ public class TableOperationDispatcher extends OperationDispatcher implements Tab
// Case 1: The table is not created by Gravitino or the external system does not support storing
// string identifier.
if (stringId == null) {
- return EntityCombinedTable.of(table)
+ TableEntity tableEntity = getEntity(ident, TABLE, TableEntity.class);
+ if (tableEntity == null) {
+ return EntityCombinedTable.of(table)
+ .withHiddenProperties(
+ getHiddenPropertyNames(
+ catalogIdentifier,
+ HasPropertyMetadata::tablePropertiesMetadata,
+ table.properties()))
+ // Some tables don't have properties or are not created by Gravitino,
+ // we can't use stringIdentifier to judge whether schema is ever imported or not.
+ // We need to check whether the entity exists.
+ .withImported(false);
+ }
+
+ return EntityCombinedTable.of(table, tableEntity)
.withHiddenProperties(
getHiddenPropertyNames(
catalogIdentifier,
@@ -473,7 +491,7 @@ public class TableOperationDispatcher extends OperationDispatcher implements Tab
// Some tables don't have properties or are not created by Gravitino,
// we can't use stringIdentifier to judge whether schema is ever imported or not.
// We need to check whether the entity exists.
- .withImported(isEntityExist(ident, TABLE));
+ .withImported(true);
}
TableEntity tableEntity =
diff --git a/core/src/main/java/org/apache/gravitino/catalog/TopicOperationDispatcher.java b/core/src/main/java/org/apache/gravitino/catalog/TopicOperationDispatcher.java
index 7ecc1107ff..63711a393c 100644
--- a/core/src/main/java/org/apache/gravitino/catalog/TopicOperationDispatcher.java
+++ b/core/src/main/java/org/apache/gravitino/catalog/TopicOperationDispatcher.java
@@ -321,11 +321,20 @@ public class TopicOperationDispatcher extends OperationDispatcher implements Top
StringIdentifier stringId = getStringIdFromProperties(topic.properties());
if (stringId == null) {
- return EntityCombinedTopic.of(topic)
+ TopicEntity topicEntity = getEntity(ident, TOPIC, TopicEntity.class);
+ if (topicEntity == null) {
+ return EntityCombinedTopic.of(topic)
+ .withHiddenProperties(
+ getHiddenPropertyNames(
+ catalogIdent, HasPropertyMetadata::topicPropertiesMetadata, topic.properties()))
+ .withImported(false);
+ }
+
+ return EntityCombinedTopic.of(topic, topicEntity)
.withHiddenProperties(
getHiddenPropertyNames(
catalogIdent, HasPropertyMetadata::topicPropertiesMetadata, topic.properties()))
- .withImported(isEntityExist(ident, TOPIC));
+ .withImported(true);
}
TopicEntity topicEntity =
diff --git a/flink-connector/flink/build.gradle.kts b/flink-connector/flink/build.gradle.kts
index 8c6b5303e6..ea0a2d0e76 100644
--- a/flink-connector/flink/build.gradle.kts
+++ b/flink-connector/flink/build.gradle.kts
@@ -43,6 +43,7 @@ val artifactName = "${rootProject.name}-flink-${flinkMajorVersion}_$scalaVersion
dependencies {
implementation(project(":core")) {
exclude("org.apache.logging.log4j")
+ exclude("org.opensearch.client")
}
implementation(project(":catalogs:catalog-common")) {
exclude("org.apache.logging.log4j")