joerghoh commented on code in PR #3176:
URL: https://github.com/apache/jackrabbit-oak/pull/3176#discussion_r4183472913
##########
oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/persistentCache/CacheMetadata.java:
##########
@@ -128,30 +137,48 @@ void clear() {
metadataMap.clear();
}
- private MetadataEntry getOrCreate(K key, boolean readFromPersistentCache) {
+ private MetadataEntry getOrCreate(K key, V value, boolean
readFromPersistentCache) {
if (!enabled) {
return null;
}
- MetadataEntry metadata = metadataMap.get(key);
- if (metadata == null) {
- MetadataEntry newEntry = new
MetadataEntry(readFromPersistentCache);
- MetadataEntry oldEntry = metadataMap.putIfAbsent(key, newEntry);
- metadata = oldEntry == null ? newEntry : oldEntry;
- }
- return metadata;
+ MetadataEntry existing = metadataMap.get(key);
+ if (existing != null && existing.isFor(value)) {
+ return existing;
+ }
+ if (existing == null) {
+ MetadataEntry created = new MetadataEntry(value,
readFromPersistentCache);
+ existing = metadataMap.putIfAbsent(key, created);
+ if (existing == null) {
+ return created;
+ }
+ if (existing.isFor(value)) {
+ return existing;
Review Comment:
just for my understanding: In this particular case this should be a valid
statement: ``assertEquals(existing, created)``.
##########
oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/persistentCache/CacheMetadata.java:
##########
@@ -128,30 +137,48 @@ void clear() {
metadataMap.clear();
}
- private MetadataEntry getOrCreate(K key, boolean readFromPersistentCache) {
+ private MetadataEntry getOrCreate(K key, V value, boolean
readFromPersistentCache) {
if (!enabled) {
return null;
}
- MetadataEntry metadata = metadataMap.get(key);
- if (metadata == null) {
- MetadataEntry newEntry = new
MetadataEntry(readFromPersistentCache);
- MetadataEntry oldEntry = metadataMap.putIfAbsent(key, newEntry);
- metadata = oldEntry == null ? newEntry : oldEntry;
- }
- return metadata;
+ MetadataEntry existing = metadataMap.get(key);
+ if (existing != null && existing.isFor(value)) {
+ return existing;
+ }
+ if (existing == null) {
+ MetadataEntry created = new MetadataEntry(value,
readFromPersistentCache);
+ existing = metadataMap.putIfAbsent(key, created);
+ if (existing == null) {
+ return created;
+ }
+ if (existing.isFor(value)) {
+ return existing;
+ }
+ }
+ return metadataMap.compute(key, (k, metadata) ->
Review Comment:
so this is the case ``existing != null && !existing.isFor(value)``, but does
the case exists where the same key is populated with different values?
##########
oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/persistentCache/CacheMetadata.java:
##########
@@ -128,30 +137,48 @@ void clear() {
metadataMap.clear();
}
- private MetadataEntry getOrCreate(K key, boolean readFromPersistentCache) {
+ private MetadataEntry getOrCreate(K key, V value, boolean
readFromPersistentCache) {
if (!enabled) {
return null;
}
- MetadataEntry metadata = metadataMap.get(key);
- if (metadata == null) {
- MetadataEntry newEntry = new
MetadataEntry(readFromPersistentCache);
- MetadataEntry oldEntry = metadataMap.putIfAbsent(key, newEntry);
- metadata = oldEntry == null ? newEntry : oldEntry;
- }
- return metadata;
+ MetadataEntry existing = metadataMap.get(key);
+ if (existing != null && existing.isFor(value)) {
+ return existing;
+ }
+ if (existing == null) {
+ MetadataEntry created = new MetadataEntry(value,
readFromPersistentCache);
+ existing = metadataMap.putIfAbsent(key, created);
+ if (existing == null) {
+ return created;
+ }
+ if (existing.isFor(value)) {
Review Comment:
In my understanding this condition is always true.
--
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]