use of uk.gov.gchq.gaffer.cache.exception.CacheOperationException in project Gaffer by gchq.
the class FederatedGraphStorage method changeGraphId.
private boolean changeGraphId(final String graphId, final String newGraphId, final Predicate<FederatedAccess> accessPredicate) throws StorageException {
boolean rtn;
final Graph graphToMove = getGraphToMove(graphId, accessPredicate);
if (nonNull(graphToMove)) {
FederatedAccess key = null;
// remove graph to be moved from storage
for (final Entry<FederatedAccess, Set<Graph>> entry : storage.entrySet()) {
final boolean removed = entry.getValue().removeIf(graph -> graph.getGraphId().equals(graphId));
if (removed) {
key = entry.getKey();
break;
}
}
// Update Tables
String storeClass = graphToMove.getStoreProperties().getStoreClass();
if (nonNull(storeClass) && storeClass.startsWith(AccumuloStore.class.getPackage().getName())) {
/*
* This logic is only for Accumulo derived stores Only.
* For updating table names to match graphs names.
*
* uk.gov.gchq.gaffer.accumulostore.[AccumuloStore, SingleUseAccumuloStore,
* SingleUseMockAccumuloStore, MockAccumuloStore, MiniAccumuloStore]
*/
try {
AccumuloProperties tmpAccumuloProps = (AccumuloProperties) graphToMove.getStoreProperties();
Connector connection = TableUtils.getConnector(tmpAccumuloProps.getInstance(), tmpAccumuloProps.getZookeepers(), tmpAccumuloProps.getUser(), tmpAccumuloProps.getPassword());
if (connection.tableOperations().exists(graphId)) {
connection.tableOperations().offline(graphId);
connection.tableOperations().rename(graphId, newGraphId);
connection.tableOperations().online(newGraphId);
}
} catch (final Exception e) {
LOGGER.warn("Error trying to update tables for graphID:{} graphToMove:{}", graphId, graphToMove);
LOGGER.warn("Error trying to update tables.", e);
}
}
final GraphConfig configWithNewGraphId = cloneGraphConfigWithNewGraphId(newGraphId, graphToMove);
// add the graph being renamed.
GraphSerialisable newGraphSerialisable = new GraphSerialisable.Builder().graph(graphToMove).config(configWithNewGraphId).build();
this.put(newGraphSerialisable, key);
// Update cache
if (isCacheEnabled()) {
try {
// Overwrite cache = true because the graphLibrary should have thrown an error before this point.
federatedStoreCache.addGraphToCache(newGraphSerialisable, key, true);
} catch (final CacheOperationException e) {
String s = "Contact Admin for recovery. Error occurred updating graphId. GraphStorage=updated, Cache=outdated graphId.";
LOGGER.error(s + " graphStorage graphId:{} cache graphId:{}", newGraphId, graphId);
throw new StorageException(s, e);
}
federatedStoreCache.deleteGraphFromCache(graphId);
}
rtn = true;
} else {
rtn = false;
}
return rtn;
}
use of uk.gov.gchq.gaffer.cache.exception.CacheOperationException in project Gaffer by gchq.
the class FederatedGraphStorage method changeGraphAccess.
private boolean changeGraphAccess(final String graphId, final FederatedAccess newFederatedAccess, final Predicate<FederatedAccess> accessPredicate) throws StorageException {
boolean rtn;
final Graph graphToMove = getGraphToMove(graphId, accessPredicate);
if (nonNull(graphToMove)) {
// remove graph to be moved
FederatedAccess oldAccess = null;
for (final Entry<FederatedAccess, Set<Graph>> entry : storage.entrySet()) {
entry.getValue().removeIf(graph -> graph.getGraphId().equals(graphId));
oldAccess = entry.getKey();
}
// add the graph being moved.
this.put(new GraphSerialisable.Builder().graph(graphToMove).build(), newFederatedAccess);
if (isCacheEnabled()) {
// Update cache
try {
federatedStoreCache.addGraphToCache(graphToMove, newFederatedAccess, true);
} catch (final CacheOperationException e) {
// TODO FS recovery
String s = "Error occurred updating graphAccess. GraphStorage=updated, Cache=outdated. graphId:" + graphId;
LOGGER.error(s + " graphStorage access:{} cache access:{}", newFederatedAccess, oldAccess);
throw new StorageException(s, e);
}
}
rtn = true;
} else {
rtn = false;
}
return rtn;
}
use of uk.gov.gchq.gaffer.cache.exception.CacheOperationException in project Gaffer by gchq.
the class FederatedStoreCache method addGraphToCache.
/**
* Add the specified {@link Graph} to the cache.
*
* @param graphSerialisable the serialised {@link Graph} to be added
* @param access Access for the graph being stored.
* @param overwrite if true, overwrite any graphs already in the cache with the same ID
* @throws CacheOperationException if there was an error trying to add to the cache
*/
public void addGraphToCache(final GraphSerialisable graphSerialisable, final FederatedAccess access, final boolean overwrite) throws CacheOperationException {
String graphId = graphSerialisable.getDeserialisedConfig().getGraphId();
Pair<GraphSerialisable, FederatedAccess> pair = new Pair<>(graphSerialisable, access);
try {
addToCache(graphId, pair, overwrite);
} catch (final CacheOperationException e) {
throw new CacheOperationException(String.format(ERROR_ADDING_GRAPH_TO_CACHE_GRAPH_ID_S, graphId), e.getCause());
}
}
Aggregations