Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Checked if near cache was available before access #13957

Merged
merged 1 commit into from Oct 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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