Skip to content

Commit

Permalink
gh-2887 stopping of a Subgraph of type FederatedStore being added whi…
Browse files Browse the repository at this point in the history
…le Cache is of type non-persistent HashMapCache
  • Loading branch information
GCHQDev404 committed Feb 23, 2023
1 parent b9fb46e commit 74eeb4b
Showing 1 changed file with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import uk.gov.gchq.gaffer.cache.CacheServiceLoader;
import uk.gov.gchq.gaffer.cache.impl.HashMapCacheService;
import uk.gov.gchq.gaffer.core.exception.GafferRuntimeException;
import uk.gov.gchq.gaffer.federatedstore.FederatedStore;
import uk.gov.gchq.gaffer.federatedstore.exception.StorageException;
import uk.gov.gchq.gaffer.federatedstore.operation.AddGraph;
Expand Down Expand Up @@ -70,6 +73,8 @@ public Void doOperation(final OP operation, final Context context, final Store s
throw new OperationException(String.format(ERROR_BUILDING_GRAPH_GRAPH_ID_S, operation.getGraphId()), e);
}

processNonViableFedStoreWithNonPersistentCaches(graphSerialisable);

Graph graph;
try {
//created at this position to capture errors before adding to cache.
Expand All @@ -93,6 +98,20 @@ public Void doOperation(final OP operation, final Context context, final Store s
return null;
}

private static void processNonViableFedStoreWithNonPersistentCaches(final GraphSerialisable graphSerialisable) throws OperationException {
final String storeClass = graphSerialisable.getStoreProperties().getStoreClass();
final Class<? extends Store> aClass;
try {
aClass = Class.forName(storeClass).asSubclass(Store.class);
} catch (ClassNotFoundException e) {
throw new GafferRuntimeException("Error creating Store class from properties", e);
}
if (FederatedStore.class.isAssignableFrom(aClass) && CacheServiceLoader.getService() instanceof HashMapCacheService) {
throw new OperationException("Error: A sub-graph of type FederatedStore cannot exist with a non-persistent cache service HashMapCacheService. " +
"The sub-graph is unusable and will loose all knowledge.");
}
}

private void overwriteCacheProperty(final OP operation, final Store store) {
/*
* FederatedStore can't survive if a subgraph changes the static
Expand Down

0 comments on commit 74eeb4b

Please sign in to comment.