jerqi commented on code in PR #3986:
URL: https://github.com/apache/gravitino/pull/3986#discussion_r1710588723
##########
core/src/main/java/org/apache/gravitino/storage/relational/JDBCBackend.java:
##########
@@ -123,36 +126,54 @@ public boolean exists(NameIdentifier ident,
Entity.EntityType entityType) throws
@Override
public <E extends Entity & HasIdentifier> void insert(E e, boolean
overwritten)
throws EntityAlreadyExistsException, IOException {
+ EntityType entityType;
Review Comment:
EntityType entityType = e.getType();
##########
core/src/main/java/org/apache/gravitino/storage/relational/JDBCBackend.java:
##########
@@ -210,32 +231,45 @@ public <E extends Entity & HasIdentifier> E get(
}
@Override
- public boolean delete(NameIdentifier ident, Entity.EntityType entityType,
boolean cascade)
- throws IOException {
- switch (entityType) {
- case METALAKE:
- return MetalakeMetaService.getInstance().deleteMetalake(ident,
cascade);
- case CATALOG:
- return CatalogMetaService.getInstance().deleteCatalog(ident, cascade);
- case SCHEMA:
- return SchemaMetaService.getInstance().deleteSchema(ident, cascade);
- case TABLE:
- return TableMetaService.getInstance().deleteTable(ident);
- case FILESET:
- return FilesetMetaService.getInstance().deleteFileset(ident);
- case TOPIC:
- return TopicMetaService.getInstance().deleteTopic(ident);
- case USER:
- return UserMetaService.getInstance().deleteUser(ident);
- case GROUP:
- return GroupMetaService.getInstance().deleteGroup(ident);
- case ROLE:
- return RoleMetaService.getInstance().deleteRole(ident);
- case TAG:
- return TagMetaService.getInstance().deleteTag(ident);
- default:
- throw new UnsupportedEntityTypeException(
- "Unsupported entity type: %s for delete operation", entityType);
+ public boolean delete(NameIdentifier ident, Entity.EntityType entityType,
boolean cascade) {
+ // Invalidate the cache first
+ EntityIdentifier entityIdentifier = EntityIdentifier.of(ident, entityType);
+ NameIdMappingService.getInstance().invalidate(entityIdentifier);
+ if (cascade) {
+ // Remove all the children entities in the cache;
+
NameIdMappingService.getInstance().invalidateWithPrefix(entityIdentifier);
+ }
+
+ try {
+ switch (entityType) {
+ case METALAKE:
+ return MetalakeMetaService.getInstance().deleteMetalake(ident,
cascade);
+ case CATALOG:
+ return CatalogMetaService.getInstance().deleteCatalog(ident,
cascade);
+ case SCHEMA:
+ return SchemaMetaService.getInstance().deleteSchema(ident, cascade);
+ case TABLE:
+ return TableMetaService.getInstance().deleteTable(ident);
+ case FILESET:
+ return FilesetMetaService.getInstance().deleteFileset(ident);
+ case TOPIC:
+ return TopicMetaService.getInstance().deleteTopic(ident);
+ case USER:
+ return UserMetaService.getInstance().deleteUser(ident);
+ case GROUP:
+ return GroupMetaService.getInstance().deleteGroup(ident);
+ case ROLE:
+ return RoleMetaService.getInstance().deleteRole(ident);
+ case TAG:
+ return TagMetaService.getInstance().deleteTag(ident);
+ default:
+ throw new UnsupportedEntityTypeException(
+ "Unsupported entity type: %s for delete operation", entityType);
+ }
+ } finally {
+ // Remove the entity from the cache again because we may add the cache
during the deletion
+ // process
+
NameIdMappingService.getInstance().invalidateWithPrefix(entityIdentifier);
Review Comment:
Maybe we should follow the pattern.
We write the slow storage first, then write the fast storage.
##########
core/src/test/java/org/apache/gravitino/storage/relational/service/TestIdNameMappingService.java:
##########
@@ -0,0 +1,54 @@
+/*
+ * 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.gravitino.storage.relational.service;
+
+import java.io.IOException;
+import org.apache.gravitino.Entity.EntityType;
+import org.apache.gravitino.NameIdentifier;
+import
org.apache.gravitino.storage.relational.service.NameIdMappingService.EntityIdentifier;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+public class TestIdNameMappingService {
+
+ @Test
+ public void testGetInstance() throws IOException {
+ NameIdMappingService instance = NameIdMappingService.getInstance();
+
+ EntityIdentifier makeLakeIdent1 =
Review Comment:
makeLake -> metalake.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]