Skip to content

Commit

Permalink
Merge pull request #13957 from ahmetmircik/fix/3.11/checkDestroyedNC
Browse files Browse the repository at this point in the history
Checked if near cache was available before access
  • Loading branch information
mmedenjak committed Oct 15, 2018
2 parents 71952a6 + 64e793b commit 99a59a1
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 4 deletions.
Expand Up @@ -116,6 +116,9 @@ public interface NearCache<K, V> extends InitializingObject {
*/
int size();


boolean isAvailable();

/**
* Gets the {@link com.hazelcast.config.InMemoryFormat} of the storage for internal records.
*
Expand Down
Expand Up @@ -136,4 +136,6 @@ public interface NearCacheRecordStore<K, V> extends InitializingObject {
long tryReserveForUpdate(K key, Data keyData);

V tryPublishReserved(K key, V value, long reservationId, boolean deserialize);

boolean isAvailable();
}
Expand Up @@ -177,6 +177,11 @@ public int size() {
return nearCacheRecordStore.size();
}

@Override
public boolean isAvailable() {
return nearCacheRecordStore.isAvailable();
}

@Override
public void preload(DataStructureAdapter<Object, ?> adapter) {
nearCacheRecordStore.loadKeys(adapter);
Expand Down
Expand Up @@ -130,6 +130,7 @@ public void setStaleReadDetector(StaleReadDetector staleReadDetector) {

@Override
public StaleReadDetector getStaleReadDetector() {
checkAvailable();
return staleReadDetector;
}

Expand Down Expand Up @@ -167,7 +168,8 @@ protected void checkAvailable() {
}
}

protected boolean isAvailable() {
@Override
public boolean isAvailable() {
return records != null;
}

Expand Down Expand Up @@ -397,6 +399,7 @@ public long tryReserveForUpdate(K key, Data keyData) {

@Override
public V tryPublishReserved(K key, V value, long reservationId, boolean deserialize) {
checkAvailable();
return updateAndGetReserved(key, value, reservationId, deserialize);
}

Expand Down
Expand Up @@ -400,5 +400,10 @@ public long tryReserveForUpdate(Integer key, Data keyData) {
public String tryPublishReserved(Integer key, String value, long reservationId, boolean deserialize) {
return null;
}

@Override
public boolean isAvailable() {
return true;
}
}
}
Expand Up @@ -443,9 +443,12 @@ public void run() {
public static void assertNearCacheSize(NearCacheTestContext<?, ?, ?, ?> context, long expectedSize, String... messages) {
String message = messages.length > 0 ? messages[0] + " " : "";

long nearCacheSize = context.nearCache.size();
assertEquals(format("%sNear Cache size didn't reach the desired value (%d vs. %d) (%s)",
message, expectedSize, nearCacheSize, context.stats), expectedSize, nearCacheSize);
if (context.nearCache.isAvailable()) {
// if near cache is destroyed, it will not be available for size check.
long nearCacheSize = context.nearCache.size();
assertEquals(format("%sNear Cache size didn't reach the desired value (%d vs. %d) (%s)",
message, expectedSize, nearCacheSize, context.stats), expectedSize, nearCacheSize);
}

long ownedEntryCount = context.stats.getOwnedEntryCount();
assertEquals(format("%sNear Cache owned entry count didn't reach the desired value (%d vs. %d) (%s)",
Expand Down

0 comments on commit 99a59a1

Please sign in to comment.