diff --git a/versioned/storage/cache/src/main/java/org/projectnessie/versioned/storage/cache/CacheBackend.java b/versioned/storage/cache/src/main/java/org/projectnessie/versioned/storage/cache/CacheBackend.java index 9164bac628d..a9d4d1e3878 100644 --- a/versioned/storage/cache/src/main/java/org/projectnessie/versioned/storage/cache/CacheBackend.java +++ b/versioned/storage/cache/src/main/java/org/projectnessie/versioned/storage/cache/CacheBackend.java @@ -31,14 +31,35 @@ * repositories. It is adviseable to have one {@link CacheBackend} per {@link Backend}. */ public interface CacheBackend { + /** + * Special sentinel reference instance to indicate that a referenc object has been marked as "not + * found". This object is only for cache-internal purposes. + */ Reference NON_EXISTENT_REFERENCE_SENTINEL = reference("NON_EXISTENT", zeroLengthObjId(), false, -1L, null); + /** + * Special sentinel object instance to indicate that an object has been marked as "not found". + * This object is only for cache-internal purposes. + */ + Obj NOT_FOUND_OBJ_SENTINEL = + new Obj() { + @Override + public ObjType type() { + throw new UnsupportedOperationException(); + } + + @Override + public ObjId id() { + throw new UnsupportedOperationException(); + } + }; + /** * Returns the {@link Obj} for the given {@link ObjId id}. * * @return One of these alternatives: the cached object if present, the {@link - * ObjCache#NOT_FOUND_OBJ_SENTINEL} indicating that the object does not exist as + * CacheBackend#NOT_FOUND_OBJ_SENTINEL} indicating that the object does not exist as * previously marked via {@link #putNegative(String, ObjId, ObjType)}, or {@code null}. */ Obj get(@Nonnull String repositoryId, @Nonnull ObjId id); @@ -79,7 +100,7 @@ public interface CacheBackend { */ void putReferenceLocal(@Nonnull String repositoryId, @Nonnull Reference r); - void putNegative(@Nonnull String repositoryId, @Nonnull String name); + void putReferenceNegative(@Nonnull String repositoryId, @Nonnull String name); static CacheBackend noopCacheBackend() { return NoopCacheBackend.INSTANCE; diff --git a/versioned/storage/cache/src/main/java/org/projectnessie/versioned/storage/cache/CachingPersistImpl.java b/versioned/storage/cache/src/main/java/org/projectnessie/versioned/storage/cache/CachingPersistImpl.java index 7b55ccc6ebf..d2adafaf904 100644 --- a/versioned/storage/cache/src/main/java/org/projectnessie/versioned/storage/cache/CachingPersistImpl.java +++ b/versioned/storage/cache/src/main/java/org/projectnessie/versioned/storage/cache/CachingPersistImpl.java @@ -16,7 +16,7 @@ package org.projectnessie.versioned.storage.cache; import static org.projectnessie.versioned.storage.cache.CacheBackend.NON_EXISTENT_REFERENCE_SENTINEL; -import static org.projectnessie.versioned.storage.cache.ObjCache.NOT_FOUND_OBJ_SENTINEL; +import static org.projectnessie.versioned.storage.cache.CacheBackend.NOT_FOUND_OBJ_SENTINEL; import jakarta.annotation.Nonnull; import java.util.Set; @@ -90,7 +90,7 @@ public T fetchTypedObj( o = persist.fetchTypedObj(id, type, typeClass); cache.putLocal(o); } catch (ObjNotFoundException e) { - cache.putNegative(id, type); + cache.putReferenceNegative(id, type); throw e; } } @@ -164,7 +164,7 @@ private T[] fetchObjsPost( r[i] = o; cache.putLocal(o); } else { - cache.putNegative(id, type); + cache.putReferenceNegative(id, type); } } } @@ -398,7 +398,7 @@ private Reference fetchReferenceInternal(@Nonnull String name, boolean bypassCac if (r == null) { r = persist.fetchReferenceForUpdate(name); if (r == null) { - cache.putNegative(name); + cache.putReferenceNegative(name); } else { cache.putReferenceLocal(r); } @@ -453,7 +453,7 @@ private Reference[] fetchReferencesInternal(@Nonnull String[] names, boolean byp r[i] = ref; cache.putReferenceLocal(ref); } else { - cache.putNegative(name); + cache.putReferenceNegative(name); } } } diff --git a/versioned/storage/cache/src/main/java/org/projectnessie/versioned/storage/cache/CaffeineCacheBackend.java b/versioned/storage/cache/src/main/java/org/projectnessie/versioned/storage/cache/CaffeineCacheBackend.java index efa09215b2d..eae99674016 100644 --- a/versioned/storage/cache/src/main/java/org/projectnessie/versioned/storage/cache/CaffeineCacheBackend.java +++ b/versioned/storage/cache/src/main/java/org/projectnessie/versioned/storage/cache/CaffeineCacheBackend.java @@ -19,7 +19,6 @@ import static java.util.Collections.singletonList; import static java.util.concurrent.TimeUnit.MICROSECONDS; import static java.util.concurrent.TimeUnit.NANOSECONDS; -import static org.projectnessie.versioned.storage.cache.ObjCache.NOT_FOUND_OBJ_SENTINEL; import static org.projectnessie.versioned.storage.common.persist.ObjType.CACHE_UNLIMITED; import static org.projectnessie.versioned.storage.common.persist.ObjType.NOT_CACHED; import static org.projectnessie.versioned.storage.serialize.ProtoSerialization.deserializeReference; @@ -227,7 +226,7 @@ public void putReferenceLocal(@Nonnull String repositoryId, @Nonnull Reference r } @Override - public void putNegative(@Nonnull String repositoryId, @Nonnull String name) { + public void putReferenceNegative(@Nonnull String repositoryId, @Nonnull String name) { if (refCacheNegativeTtlNanos <= 0L) { return; } diff --git a/versioned/storage/cache/src/main/java/org/projectnessie/versioned/storage/cache/DistributedInvalidationsCacheBackend.java b/versioned/storage/cache/src/main/java/org/projectnessie/versioned/storage/cache/DistributedInvalidationsCacheBackend.java index c4b7202203e..4f1765e711e 100644 --- a/versioned/storage/cache/src/main/java/org/projectnessie/versioned/storage/cache/DistributedInvalidationsCacheBackend.java +++ b/versioned/storage/cache/src/main/java/org/projectnessie/versioned/storage/cache/DistributedInvalidationsCacheBackend.java @@ -113,7 +113,7 @@ public void putReference(@Nonnull String repositoryId, @Nonnull Reference r) { } @Override - public void putNegative(@Nonnull String repositoryId, @Nonnull String name) { - local.putNegative(repositoryId, name); + public void putReferenceNegative(@Nonnull String repositoryId, @Nonnull String name) { + local.putReferenceNegative(repositoryId, name); } } diff --git a/versioned/storage/cache/src/main/java/org/projectnessie/versioned/storage/cache/NoopCacheBackend.java b/versioned/storage/cache/src/main/java/org/projectnessie/versioned/storage/cache/NoopCacheBackend.java index 445d15b4f30..df661573554 100644 --- a/versioned/storage/cache/src/main/java/org/projectnessie/versioned/storage/cache/NoopCacheBackend.java +++ b/versioned/storage/cache/src/main/java/org/projectnessie/versioned/storage/cache/NoopCacheBackend.java @@ -34,7 +34,7 @@ public Persist wrap(@Nonnull Persist perist) { } @Override - public void putNegative(@Nonnull String repositoryId, @Nonnull String name) {} + public void putReferenceNegative(@Nonnull String repositoryId, @Nonnull String name) {} @Override public void putReference(@Nonnull String repositoryId, @Nonnull Reference r) {} diff --git a/versioned/storage/cache/src/main/java/org/projectnessie/versioned/storage/cache/ObjCache.java b/versioned/storage/cache/src/main/java/org/projectnessie/versioned/storage/cache/ObjCache.java index 4f0e353842d..c87030d46c5 100644 --- a/versioned/storage/cache/src/main/java/org/projectnessie/versioned/storage/cache/ObjCache.java +++ b/versioned/storage/cache/src/main/java/org/projectnessie/versioned/storage/cache/ObjCache.java @@ -29,8 +29,8 @@ public interface ObjCache { * Returns the {@link Obj} for the given {@link ObjId id}. * * @return One of these alternatives: the cached object if present, the {@link - * #NOT_FOUND_OBJ_SENTINEL} indicating that the object does not exist as previously - * marked via {@link #putNegative(ObjId, ObjType)}, or {@code null}. + * CacheBackend#NOT_FOUND_OBJ_SENTINEL} indicating that the object does not exist as + * previously marked via {@link #putReferenceNegative(ObjId, ObjType)}, or {@code null}. */ Obj get(@Nonnull ObjId id); @@ -47,7 +47,7 @@ public interface ObjCache { * Record the "not found" sentinel for the given {@link ObjId id} and {@link ObjType type}. * Behaves like {@link #remove(ObjId)}, if {@code type} is {@code null}. */ - void putNegative(ObjId id, ObjType type); + void putReferenceNegative(ObjId id, ObjType type); void remove(@Nonnull ObjId id); @@ -68,23 +68,5 @@ public interface ObjCache { */ void putReferenceLocal(@Nonnull Reference r); - void putNegative(@Nonnull String name); - - /** - * Special sentinel object instance to indicate that an object has been marked as "not found" via - * {@link #putNegative(ObjId, ObjType)}, returned from {@link #get(ObjId)}. This object is only - * for cache-internal purposes. - */ - Obj NOT_FOUND_OBJ_SENTINEL = - new Obj() { - @Override - public ObjType type() { - throw new UnsupportedOperationException(); - } - - @Override - public ObjId id() { - throw new UnsupportedOperationException(); - } - }; + void putReferenceNegative(@Nonnull String name); } diff --git a/versioned/storage/cache/src/main/java/org/projectnessie/versioned/storage/cache/ObjCacheImpl.java b/versioned/storage/cache/src/main/java/org/projectnessie/versioned/storage/cache/ObjCacheImpl.java index fc8d7cd70bf..a361426c15d 100644 --- a/versioned/storage/cache/src/main/java/org/projectnessie/versioned/storage/cache/ObjCacheImpl.java +++ b/versioned/storage/cache/src/main/java/org/projectnessie/versioned/storage/cache/ObjCacheImpl.java @@ -47,7 +47,7 @@ public void putLocal(@Nonnull Obj obj) { } @Override - public void putNegative(ObjId id, ObjType type) { + public void putReferenceNegative(ObjId id, ObjType type) { if (type != null) { backend.putNegative(repositoryId, id, type); } else { @@ -86,7 +86,7 @@ public Reference getReference(@Nonnull String name) { } @Override - public void putNegative(@Nonnull String name) { - backend.putNegative(repositoryId, name); + public void putReferenceNegative(@Nonnull String name) { + backend.putReferenceNegative(repositoryId, name); } }