jerryshao commented on code in PR #7354:
URL: https://github.com/apache/gravitino/pull/7354#discussion_r2141637907
##########
core/src/main/java/org/apache/gravitino/storage/relational/RelationalEntityStore.java:
##########
@@ -83,47 +106,91 @@ private static RelationalBackend
createRelationalEntityBackend(Config config) {
@Override
public <E extends Entity & HasIdentifier> List<E> list(
Namespace namespace, Class<E> type, Entity.EntityType entityType) throws
IOException {
- return backend.list(namespace, entityType, false);
+ return cache.withCacheLock(
+ () -> {
+ List<E> entities = backend.list(namespace, entityType, false);
+ if (namespaceSet.add(namespace)) {
+ entities.forEach(cache::put);
+ }
+
+ return entities;
+ });
}
@Override
public <E extends Entity & HasIdentifier> List<E> list(
Namespace namespace, Class<E> type, Entity.EntityType entityType,
boolean allFields)
throws IOException {
- return backend.list(namespace, entityType, allFields);
+ return cache.withCacheLock(
+ () -> {
+ List<E> entities = backend.list(namespace, entityType, allFields);
+ if (namespaceSet.add(namespace)) {
+ entities.forEach(cache::put);
+ }
+
+ return entities;
+ });
}
@Override
public boolean exists(NameIdentifier ident, Entity.EntityType entityType)
throws IOException {
- return backend.exists(ident, entityType);
+ boolean existsInCache = cache.contains(ident, entityType);
+ return existsInCache || backend.exists(ident, entityType);
}
@Override
public <E extends Entity & HasIdentifier> void put(E e, boolean overwritten)
throws IOException, EntityAlreadyExistsException {
- backend.insert(e, overwritten);
+ cache.withCacheLock(
+ () -> {
+ backend.insert(e, overwritten);
+
+ if (e.type() == Entity.EntityType.MODEL_VERSION) {
+ NameIdentifier modelIdent = ((ModelVersionEntity)
e).modelIdentifier();
+ cache.invalidate(modelIdent, Entity.EntityType.MODEL);
+ }
Review Comment:
What is the purpose of this code?
--
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]