Skip to content

Commit

Permalink
gh-2435 Updating Tables for changeGraphIds
Browse files Browse the repository at this point in the history
  • Loading branch information
GCHQDev404 committed Jun 3, 2021
1 parent 8467703 commit d08202c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
1 change: 0 additions & 1 deletion store-implementation/federated-store/pom.xml
Expand Up @@ -44,7 +44,6 @@
<groupId>uk.gov.gchq.gaffer</groupId>
<artifactId>accumulo-store</artifactId>
<version>${project.parent.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>uk.gov.gchq.gaffer</groupId>
Expand Down
Expand Up @@ -17,9 +17,11 @@
package uk.gov.gchq.gaffer.federatedstore;

import com.google.common.collect.Sets;
import org.apache.accumulo.core.client.Connector;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import uk.gov.gchq.gaffer.accumulostore.AccumuloStore;
import uk.gov.gchq.gaffer.cache.CacheServiceLoader;
import uk.gov.gchq.gaffer.cache.exception.CacheOperationException;
import uk.gov.gchq.gaffer.commonutil.JsonUtil;
Expand All @@ -32,6 +34,7 @@
import uk.gov.gchq.gaffer.graph.GraphSerialisable;
import uk.gov.gchq.gaffer.operation.OperationException;
import uk.gov.gchq.gaffer.store.Context;
import uk.gov.gchq.gaffer.store.Store;
import uk.gov.gchq.gaffer.store.StoreTrait;
import uk.gov.gchq.gaffer.store.library.GraphLibrary;
import uk.gov.gchq.gaffer.store.operation.GetSchema;
Expand Down Expand Up @@ -618,6 +621,26 @@ private boolean changeGraphId(final String graphId, final String newGraphId, fin
}
}

//Update Tables
String storeClass = graphToMove.getStoreProperties().getStoreClass();
if (nonNull(storeClass) && storeClass.startsWith(AccumuloStore.class.getPackage().getName())) {
Store tmpStore = Store.createStore(graphId, graphToMove.getSchema(), graphToMove.getStoreProperties());
if (tmpStore instanceof AccumuloStore) {
AccumuloStore accumuloStore = ((AccumuloStore) tmpStore);
try {
Connector connection = accumuloStore.getConnection();
if (connection.tableOperations().exists(graphId)) {
connection.tableOperations().offline(graphId);
connection.tableOperations().clone(graphId, newGraphId, true, null, null);
connection.tableOperations().delete(graphId);
}
} catch (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.
Expand Down

0 comments on commit d08202c

Please sign in to comment.