jerqi commented on code in PR #7734:
URL: https://github.com/apache/gravitino/pull/7734#discussion_r2275281982
##########
core/src/main/java/org/apache/gravitino/storage/relational/RelationalEntityStore.java:
##########
@@ -260,4 +261,58 @@ public <E extends Entity & HasIdentifier> List<E>
updateEntityRelations(
return backend.updateEntityRelations(
relType, srcEntityIdent, srcEntityType, destEntitiesToAdd,
destEntitiesToRemove);
}
+
+ @Override
+ public <E extends Entity & HasIdentifier> Void insertEntitiesAndRelations(
+ Type relType, List<Entity.RelationalEntity<E>> relationalEntities,
boolean overwrite)
+ throws IOException {
+ for (Entity.RelationalEntity<E> relationalEntity : relationalEntities) {
+ if (relationalEntity.vertexType() == Relation.VertexType.SOURCE) {
+
+ // If the source vertex is being inserted, we invalidate the relations
+ // The key of the relation is source name identifier and entity type
+ cache.invalidate(
+ relationalEntity.entity().nameIdentifier(),
relationalEntity.entity().type(), relType);
+
+ // If the source vertex is being inserted, we invalidate the cache for
the source vertex
+ cache.invalidate(
+ relationalEntity.entity().nameIdentifier(),
relationalEntity.entity().type());
+ } else {
+
+ // If the dest vertex is being inserted, we invalidate the relations
+ // The key of the relation is source name identifier and entity type
+ for (NameIdentifier relatedNameIdent :
relationalEntity.relatedNameIdentifiers()) {
+ cache.invalidate(relatedNameIdent,
relationalEntity.relatedEntityType(), relType);
+ }
+
+ // If the dest vertex is being inserted, we invalidate the cache for
the dest vertex
+ cache.invalidate(
+ relationalEntity.entity().nameIdentifier(),
relationalEntity.entity().type());
+ }
+ }
+
+ backend.insertEntitiesAndRelations(relType, relationalEntities, overwrite);
+ return null;
+ }
+
+ @Override
+ public int deleteEntitiesAndRelations(
+ Type relType, Relation.VertexType deleteVertexType, List<Relation>
relations)
+ throws IOException {
+ // Invalid every relation in the cache before deleting them.
+ // The relation's key is source name identifier and entity type
+ for (Relation relation : relations) {
+ cache.invalidate(relation.getSourceIdent(), relation.getSourceType(),
relType);
+
+ // If we delete source vertex, we invalidate the source vertex in the
cache
+ if (deleteVertexType == Relation.VertexType.SOURCE) {
+ cache.invalidate(relation.getSourceIdent(), relation.getSourceType());
+ } else {
+ // If we delete dest vertex, we invalidate the dest vertex in the cache
+ cache.invalidate(relation.getDestIdent(), relation.getDestType());
+ }
+ }
Review Comment:
I have added a lock in the upper layer, the operations are memory
operations. It's better to provide a interface to batch invalidate the
relations. I will add an interface to provide the ability.
--
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]