Skip to content

Commit

Permalink
review
Browse files Browse the repository at this point in the history
  • Loading branch information
snazy committed Jun 11, 2024
1 parent ef91cf7 commit f16eaab
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 <em>not</em> exist as
* CacheBackend#NOT_FOUND_OBJ_SENTINEL} indicating that the object does <em>not</em> exist as
* previously marked via {@link #putNegative(String, ObjId, ObjType)}, or {@code null}.
*/
Obj get(@Nonnull String repositoryId, @Nonnull ObjId id);
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -90,7 +90,7 @@ public <T extends Obj> T fetchTypedObj(
o = persist.fetchTypedObj(id, type, typeClass);
cache.putLocal(o);
} catch (ObjNotFoundException e) {
cache.putNegative(id, type);
cache.putReferenceNegative(id, type);
throw e;
}
}
Expand Down Expand Up @@ -164,7 +164,7 @@ private <T extends Obj> T[] fetchObjsPost(
r[i] = o;
cache.putLocal(o);
} else {
cache.putNegative(id, type);
cache.putReferenceNegative(id, type);
}
}
}
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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) {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <em>not</em> exist as previously
* marked via {@link #putNegative(ObjId, ObjType)}, or {@code null}.
* CacheBackend#NOT_FOUND_OBJ_SENTINEL} indicating that the object does <em>not</em> exist as
* previously marked via {@link #putReferenceNegative(ObjId, ObjType)}, or {@code null}.
*/
Obj get(@Nonnull ObjId id);

Expand All @@ -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);

Expand All @@ -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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
}
}

0 comments on commit f16eaab

Please sign in to comment.