/** * Ensures the given Accumulo namespace exist, creating it if necessary * * @param schema Presto schema (Accumulo namespace) */ public void ensureNamespace(String schema) { try { // If the table schema is not "default" and the namespace does not exist, create it if (!schema.equals(DEFAULT) && !connector.namespaceOperations().exists(schema)) { connector.namespaceOperations().create(schema); } } catch (AccumuloException | AccumuloSecurityException e) { throw new PrestoException(UNEXPECTED_ACCUMULO_ERROR, "Failed to check for existence or create Accumulo namespace", e); } catch (NamespaceExistsException e) { // Suppress race condition between test for existence and creation LOG.warn("NamespaceExistsException suppressed when creating " + schema); } }
@Override public int execute(final String fullCommand, final CommandLine cl, final Shell shellState) throws AccumuloException, AccumuloSecurityException, TableExistsException, TableNotFoundException, IOException, ClassNotFoundException, NamespaceExistsException, NamespaceNotFoundException { if (createNamespaceOptCopyConfig == null) { getOptions(); } String namespace = cl.getArgs()[0]; shellState.getAccumuloClient().namespaceOperations().create(namespace); // Copy options if flag was set Iterable<Entry<String,String>> configuration = null; if (cl.hasOption(createNamespaceOptCopyConfig.getOpt())) { String copy = cl.getOptionValue(createNamespaceOptCopyConfig.getOpt()); if (shellState.getAccumuloClient().namespaceOperations().exists(namespace)) { configuration = shellState.getAccumuloClient().namespaceOperations().getProperties(copy); } } if (configuration != null) { for (Entry<String,String> entry : configuration) { if (Property.isValidTablePropertyKey(entry.getKey())) { shellState.getAccumuloClient().namespaceOperations().setProperty(namespace, entry.getKey(), entry.getValue()); } } } return 0; }
private void createNamespaceIfNecessary(NamespaceOperations namespaceOperations, String table) throws AccumuloException, AccumuloSecurityException { // if the table has a namespace in it that doesn't already exist, create it if (table.contains(".")) { String namespace = table.split("\\.")[0]; try { if (!namespaceOperations.exists(namespace)) { namespaceOperations.create(namespace); } } catch (NamespaceExistsException e) { // in this case, somebody else must have created the namespace after our existence check log.info("Tried to create Accumulo namespace," + namespace + ", but it already exists"); } } } }
private void createNamespaceIfNecessary(NamespaceOperations namespaceOperations, String table) throws AccumuloException, AccumuloSecurityException { // if the table has a namespace in it that doesn't already exist, create it if (table.contains(".")) { String namespace = table.split("\\.")[0]; try { if (!namespaceOperations.exists(namespace)) { namespaceOperations.create(namespace); } } catch (NamespaceExistsException e) { // in this case, somebody else must have created the namespace after our existence check log.info("Tried to create " + namespace + " but somebody beat us to the punch"); } } }
@Override public void visit(State state, Environment env, Properties props) throws Exception { Connector conn = env.getConnector(); Random rand = (Random) state.get("rand"); @SuppressWarnings("unchecked") List<String> namespaces = (List<String>) state.get("namespaces"); String namespace = namespaces.get(rand.nextInt(namespaces.size())); try { conn.namespaceOperations().create(namespace); log.debug("Created namespace " + namespace); } catch (NamespaceExistsException e) { log.debug("Create namespace " + namespace + " failed, it exists"); } } }
@Override public void createNamespace(ByteBuffer login, String namespaceName) throws org.apache.accumulo.proxy.thrift.AccumuloException, org.apache.accumulo.proxy.thrift.AccumuloSecurityException, org.apache.accumulo.proxy.thrift.NamespaceExistsException, TException { try { getConnector(login).namespaceOperations().create(namespaceName); } catch (NamespaceExistsException e) { throw new org.apache.accumulo.proxy.thrift.NamespaceExistsException(e.toString()); } catch (Exception e) { handleException(e); } }
@Override public int execute(final String fullCommand, final CommandLine cl, final Shell shellState) throws AccumuloException, AccumuloSecurityException, TableExistsException, TableNotFoundException, IOException, ClassNotFoundException, NamespaceExistsException, NamespaceNotFoundException { if (createNamespaceOptCopyConfig == null) { getOptions(); } String namespace = cl.getArgs()[0]; shellState.getConnector().namespaceOperations().create(namespace); // Copy options if flag was set Iterable<Entry<String,String>> configuration = null; if (cl.hasOption(createNamespaceOptCopyConfig.getOpt())) { String copy = cl.getOptionValue(createNamespaceOptCopyConfig.getOpt()); if (shellState.getConnector().namespaceOperations().exists(namespace)) { configuration = shellState.getConnector().namespaceOperations().getProperties(copy); } } if (configuration != null) { for (Entry<String,String> entry : configuration) { if (Property.isValidTablePropertyKey(entry.getKey())) { shellState.getConnector().namespaceOperations().setProperty(namespace, entry.getKey(), entry.getValue()); } } } return 0; }
@Test public void missingVolumePreferredVolumeChooser() throws Exception { log.info("Starting missingVolumePreferredVolumeChooser"); // Create namespace Connector connector = getConnector(); connector.namespaceOperations().create(namespace1); // Set properties on the namespace String propertyName = Property.TABLE_VOLUME_CHOOSER.getKey(); String volume = PreferredVolumeChooser.class.getName(); connector.namespaceOperations().setProperty(namespace1, propertyName, volume); // Create table1 on namespace1 String tableName = namespace1 + ".1"; connector.tableOperations().create(tableName); String tableID = connector.tableOperations().tableIdMap().get(tableName); // Add 10 splits to the table addSplits(connector, tableName); // Write some data to the table writeAndReadData(connector, tableName); // Verify the new files are written to the Volumes specified verifyVolumes(connector, tableName, TabletsSection.getRange(tableID), v1.toString() + "," + v2.toString() + "," + v4.toString()); }
@Test public void notInstancePreferredVolumeChooser() throws Exception { log.info("Starting notInstancePreferredVolumeChooser"); // Create namespace Connector connector = getConnector(); connector.namespaceOperations().create(namespace1); // Set properties on the namespace String propertyName = Property.TABLE_VOLUME_CHOOSER.getKey(); String volume = PreferredVolumeChooser.class.getName(); connector.namespaceOperations().setProperty(namespace1, propertyName, volume); propertyName = "table.custom.preferredVolumes"; volume = v3.toString(); connector.namespaceOperations().setProperty(namespace1, propertyName, volume); // Create table1 on namespace1 String tableName = namespace1 + ".1"; connector.tableOperations().create(tableName); String tableID = connector.tableOperations().tableIdMap().get(tableName); // Add 10 splits to the table addSplits(connector, tableName); // Write some data to the table writeAndReadData(connector, tableName); // Verify the new files are written to the Volumes specified verifyVolumes(connector, tableName, TabletsSection.getRange(tableID), v1.toString() + "," + v2.toString() + "," + v4.toString()); }
assertNull(map.get(namespace)); c.namespaceOperations().create(namespace); namespaces = c.namespaceOperations().list(); map = c.namespaceOperations().namespaceIdMap();
@Test public void verifySystemPropertyInheritance() throws Exception { String t1 = "1"; String t2 = namespace + "." + t1; c.tableOperations().create(t1); c.namespaceOperations().create(namespace); c.tableOperations().create(t2); // verify iterator inheritance _verifySystemPropertyInheritance(t1, t2, Property.TABLE_ITERATOR_PREFIX.getKey() + "scan.sum", "20," + SimpleFilter.class.getName(), false); // verify constraint inheritance _verifySystemPropertyInheritance(t1, t2, Property.TABLE_CONSTRAINT_PREFIX.getKey() + "42", NumericValueConstraint.class.getName(), false); // verify other inheritance _verifySystemPropertyInheritance(t1, t2, Property.TABLE_LOCALITY_GROUP_PREFIX.getKey() + "dummy", "dummy", true); }
try { if (!conn.namespaceOperations().exists(namespace)) { conn.namespaceOperations().create(namespace);
@Test public void verifyIteratorInheritance() throws Exception { String t1 = namespace + ".1"; c.namespaceOperations().create(namespace); c.tableOperations().create(t1); String iterName = namespace + "_iter";
@Test(expected = NamespaceNotEmptyException.class) public void deleteNonEmptyNamespace() throws Exception { String tableName1 = namespace + ".1"; assertFalse(c.namespaceOperations().exists(namespace)); assertFalse(c.tableOperations().exists(tableName1)); c.namespaceOperations().create(namespace); c.tableOperations().create(tableName1); assertTrue(c.namespaceOperations().exists(namespace)); assertTrue(c.tableOperations().exists(tableName1)); c.namespaceOperations().delete(namespace); // should fail }
@Test public void renameNamespaceWithTable() throws Exception { String namespace2 = namespace + "_renamed"; String t1 = namespace + ".t"; String t2 = namespace2 + ".t"; c.namespaceOperations().create(namespace); c.tableOperations().create(t1); assertTrue(c.namespaceOperations().exists(namespace)); assertTrue(c.tableOperations().exists(t1)); assertFalse(c.namespaceOperations().exists(namespace2)); assertFalse(c.tableOperations().exists(t2)); String namespaceId = c.namespaceOperations().namespaceIdMap().get(namespace); String tableId = c.tableOperations().tableIdMap().get(t1); c.namespaceOperations().rename(namespace, namespace2); assertFalse(c.namespaceOperations().exists(namespace)); assertFalse(c.tableOperations().exists(t1)); assertTrue(c.namespaceOperations().exists(namespace2)); assertTrue(c.tableOperations().exists(t2)); // verify id's didn't change String namespaceId2 = c.namespaceOperations().namespaceIdMap().get(namespace2); String tableId2 = c.tableOperations().tableIdMap().get(t2); assertEquals(namespaceId, namespaceId2); assertEquals(tableId, tableId2); }
assertEquals(NamespaceNotFoundException.class.getName(), e.getCause().getClass().getName()); c.namespaceOperations().create(namespace); assertTrue(c.namespaceOperations().exists(namespace)); assertFalse(c.tableOperations().exists(t1));