use of uk.gov.gchq.gaffer.accumulostore.key.AccumuloRuntimeException in project Gaffer by gchq.
the class TableUtils method ensureTableExists.
/**
* Ensures that the table exists, otherwise it creates it and sets it up to
* receive Gaffer data
*
* @param store the accumulo store
* @throws StoreException if a connection to accumulo could not be created or there is a failure to create a table/iterator
*/
public static void ensureTableExists(final AccumuloStore store) throws StoreException {
final String tableName = store.getProperties().getTable();
if (null == tableName) {
throw new AccumuloRuntimeException("Table name is required.");
}
final Connector connector = store.getConnection();
if (!connector.tableOperations().exists(tableName)) {
try {
TableUtils.createTable(store);
} catch (final TableExistsException e) {
// The method to create a table is synchronised, if you are using the same store only through one client in one JVM you shouldn't get here
// Someone else got there first, never mind...
}
}
}
use of uk.gov.gchq.gaffer.accumulostore.key.AccumuloRuntimeException in project Gaffer by gchq.
the class TableUtils method createTable.
/**
* Creates a table for Gaffer data and enables the correct Bloom filter;
* removes the versioning iterator and adds an aggregator Iterator the
* {@link org.apache.accumulo.core.iterators.user.AgeOffFilter} for the
* specified time period.
*
* @param store the accumulo store
* @throws StoreException failure to create accumulo connection or add iterator settings
* @throws TableExistsException failure to create table
*/
public static synchronized void createTable(final AccumuloStore store) throws StoreException, TableExistsException {
// Create table
final String tableName = store.getProperties().getTable();
if (null == tableName) {
throw new AccumuloRuntimeException("Table name is required.");
}
final Connector connector = store.getConnection();
if (connector.tableOperations().exists(tableName)) {
LOGGER.info("Table {} exists, not creating", tableName);
return;
}
try {
LOGGER.info("Creating table {} as user {}", tableName, connector.whoami());
connector.tableOperations().create(tableName);
final String repFactor = store.getProperties().getTableFileReplicationFactor();
if (null != repFactor) {
LOGGER.info("Table file replication set to {} on table {}", repFactor, tableName);
connector.tableOperations().setProperty(tableName, Property.TABLE_FILE_REPLICATION.getKey(), repFactor);
}
// Enable Bloom filters using ElementFunctor
LOGGER.info("Enabling Bloom filter on table {}", tableName);
connector.tableOperations().setProperty(tableName, Property.TABLE_BLOOM_ENABLED.getKey(), "true");
connector.tableOperations().setProperty(tableName, Property.TABLE_BLOOM_KEY_FUNCTOR.getKey(), store.getKeyPackage().getKeyFunctor().getClass().getName());
// Remove versioning iterator from table for all scopes
LOGGER.info("Removing versioning iterator from table {}", tableName);
final EnumSet<IteratorScope> iteratorScopes = EnumSet.allOf(IteratorScope.class);
connector.tableOperations().removeIterator(tableName, "vers", iteratorScopes);
if (store.getSchema().hasAggregators()) {
// Add Combiner iterator to table for all scopes
LOGGER.info("Adding Aggregator iterator to table {} for all scopes", tableName);
connector.tableOperations().attachIterator(tableName, store.getKeyPackage().getIteratorFactory().getAggregatorIteratorSetting(store));
} else {
LOGGER.info("Aggregator iterator has not been added to table {}", tableName);
}
if (store.getProperties().getEnableValidatorIterator()) {
// Add validator iterator to table for all scopes
LOGGER.info("Adding Validator iterator to table {} for all scopes", tableName);
connector.tableOperations().attachIterator(tableName, store.getKeyPackage().getIteratorFactory().getValidatorIteratorSetting(store));
} else {
LOGGER.info("Validator iterator has not been added to table {}", tableName);
}
} catch (AccumuloSecurityException | TableNotFoundException | AccumuloException | IteratorSettingException e) {
throw new StoreException(e.getMessage(), e);
}
setLocalityGroups(store);
}
Aggregations