Skip to content

Commit

Permalink
check schema
Browse files Browse the repository at this point in the history
  • Loading branch information
Heng Qin committed Jun 5, 2024
1 parent d5ca7e7 commit d0910a7
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 22 deletions.
10 changes: 10 additions & 0 deletions core/src/main/java/com/datastrato/gravitino/GravitinoEnv.java
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,16 @@ public void setCatalogDispatcher(CatalogDispatcher catalogDispatcher) {
this.catalogDispatcher = catalogDispatcher;
}

/**
* This method is used for testing purposes only to set the schema dispatcher for test.
*
* @param schemaDispatcher The schema dispatcher to be set.
*/
@VisibleForTesting
public void setSchemaDispatcher(SchemaDispatcher schemaDispatcher) {
this.schemaDispatcher = schemaDispatcher;
}

/**
* This method is used for testing purposes only to set the entity store for test in package
* `com.datastrato.gravitino.authorization`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,7 @@ public Schema alterSchema(NameIdentifier ident, SchemaChange... changes)
getHiddenPropertyNames(
catalogIdent,
HasPropertyMetadata::schemaPropertiesMetadata,
alteredSchema.properties()))
.withImported(true);
alteredSchema.properties()));
}

StringIdentifier stringId = getStringIdFromProperties(alteredSchema.properties());
Expand All @@ -226,8 +225,7 @@ public Schema alterSchema(NameIdentifier ident, SchemaChange... changes)
getHiddenPropertyNames(
catalogIdent,
HasPropertyMetadata::schemaPropertiesMetadata,
alteredSchema.properties()))
.withImported(isEntityExist(ident));
alteredSchema.properties()));
}

SchemaEntity updatedSchemaEntity =
Expand Down Expand Up @@ -255,15 +253,12 @@ public Schema alterSchema(NameIdentifier ident, SchemaChange... changes)
"UPDATE",
stringId.id());

boolean imported = updatedSchemaEntity != null;

return EntityCombinedSchema.of(alteredSchema, updatedSchemaEntity)
.withHiddenPropertiesSet(
getHiddenPropertyNames(
catalogIdent,
HasPropertyMetadata::schemaPropertiesMetadata,
alteredSchema.properties()))
.withImported(imported);
alteredSchema.properties()));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import static com.datastrato.gravitino.rel.expressions.transforms.Transforms.EMPTY_TRANSFORM;

import com.datastrato.gravitino.EntityStore;
import com.datastrato.gravitino.GravitinoEnv;
import com.datastrato.gravitino.NameIdentifier;
import com.datastrato.gravitino.Namespace;
import com.datastrato.gravitino.StringIdentifier;
Expand Down Expand Up @@ -88,8 +89,12 @@ public Table loadTable(NameIdentifier ident) throws NoSuchTableException {
return table;
}

TreeLockUtils.doWithTreeLock(
NameIdentifier.of(ident.namespace().levels()), LockType.WRITE, () -> importTable(ident));
if (GravitinoEnv.getInstance()
.schemaDispatcher()
.schemaExists(NameIdentifier.of(ident.namespace().levels()))) {
TreeLockUtils.doWithTreeLock(
NameIdentifier.of(ident.namespace().levels()), LockType.WRITE, () -> importTable(ident));
}

return table;
}
Expand Down Expand Up @@ -231,8 +236,7 @@ public Table alterTable(NameIdentifier ident, TableChange... changes)
getHiddenPropertyNames(
getCatalogIdentifier(ident),
HasPropertyMetadata::tablePropertiesMetadata,
alteredTable.properties()))
.withImported(isEntityExist(ident));
alteredTable.properties()));
}

TableEntity updatedTableEntity =
Expand Down Expand Up @@ -267,15 +271,12 @@ public Table alterTable(NameIdentifier ident, TableChange... changes)
"UPDATE",
stringId.id());

boolean imported = updatedTableEntity != null;

return EntityCombinedTable.of(alteredTable, updatedTableEntity)
.withHiddenPropertiesSet(
getHiddenPropertyNames(
getCatalogIdentifier(ident),
HasPropertyMetadata::tablePropertiesMetadata,
alteredTable.properties()))
.withImported(imported);
alteredTable.properties()));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import static com.datastrato.gravitino.catalog.PropertiesMetadataHelpers.validatePropertyForCreate;

import com.datastrato.gravitino.EntityStore;
import com.datastrato.gravitino.GravitinoEnv;
import com.datastrato.gravitino.NameIdentifier;
import com.datastrato.gravitino.Namespace;
import com.datastrato.gravitino.StringIdentifier;
Expand Down Expand Up @@ -79,8 +80,12 @@ public Topic loadTopic(NameIdentifier ident) throws NoSuchTopicException {
return topic;
}

TreeLockUtils.doWithTreeLock(
NameIdentifier.of(ident.namespace().levels()), LockType.WRITE, () -> importTopic(ident));
if (GravitinoEnv.getInstance()
.schemaDispatcher()
.schemaExists(NameIdentifier.of(ident.namespace().levels()))) {
TreeLockUtils.doWithTreeLock(
NameIdentifier.of(ident.namespace().levels()), LockType.WRITE, () -> importTopic(ident));
}
return topic;
}

Expand Down Expand Up @@ -219,15 +224,12 @@ public Topic alterTopic(NameIdentifier ident, TopicChange... changes)
"UPDATE",
getStringIdFromProperties(alteredTopic.properties()).id());

boolean imported = updatedTopicEntity != null;

return EntityCombinedTopic.of(alteredTopic, updatedTopicEntity)
.withHiddenPropertiesSet(
getHiddenPropertyNames(
catalogIdent,
HasPropertyMetadata::topicPropertiesMetadata,
alteredTopic.properties()))
.withImported(imported);
alteredTopic.properties()));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public static void initialize() throws IOException {
doReturn(1000L).when(config).get(TREE_LOCK_MIN_NODE_IN_MEMORY);
doReturn(36000L).when(config).get(TREE_LOCK_CLEAN_INTERVAL);
GravitinoEnv.getInstance().setLockManager(new LockManager(config));
GravitinoEnv.getInstance().setSchemaDispatcher(schemaOperationDispatcher);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public static void initialize() throws IOException {
doReturn(1000L).when(config).get(TREE_LOCK_MIN_NODE_IN_MEMORY);
doReturn(36000L).when(config).get(TREE_LOCK_CLEAN_INTERVAL);
GravitinoEnv.getInstance().setLockManager(new LockManager(config));
GravitinoEnv.getInstance().setSchemaDispatcher(schemaOperationDispatcher);
}

@Test
Expand Down

0 comments on commit d0910a7

Please sign in to comment.