if (!verbose) { for (Text row : maxSplits > 0 ? shellState.getAccumuloClient().tableOperations().listSplits(tableName, maxSplits) : shellState.getAccumuloClient().tableOperations().listSplits(tableName)) { p.print(encode(encode, row));
new TreeSet<>(shellState.getAccumuloClient().tableOperations().listSplits(oldTable)));
private static void checkMetadataSplits(int numSplits, TableOperations opts) throws AccumuloSecurityException, TableNotFoundException, AccumuloException, InterruptedException { for (int i = 0; i < 10; i++) { if (opts.listSplits(MetadataTable.NAME).size() == numSplits) { break; } Thread.sleep(2000); } Collection<Text> splits = opts.listSplits(MetadataTable.NAME); assertEquals("Actual metadata table splits: " + splits, numSplits, splits.size()); }
@Override public void run() { while (!stop.get()) { UtilWaitThread.sleep(1000); try { log.info("splits: " + tableOperations.listSplits(tableName).size()); } catch (TableNotFoundException | AccumuloException | AccumuloSecurityException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } };
static public void checkSplits(Connector c, String table, int min, int max) throws Exception { Collection<Text> splits = c.tableOperations().listSplits(table); if (splits.size() < min || splits.size() > max) { throw new Exception("# of table splits points out of range, #splits=" + splits.size() + " table=" + table + " min=" + min + " max=" + max); } }
/** Copy the splits placed on table t1 to table t2. */ public static void copySplits(TableOperations tops, String t1, String t2) throws AccumuloException { try { Collection<Text> splits = tops.listSplits(t1); SortedSet<Text> ss = new TreeSet<>(splits); tops.addSplits(t2, ss); } catch (TableNotFoundException | AccumuloSecurityException e) { log.error("cannot handle splits copying from "+t1+" to "+t2, e); throw new RuntimeException(e); } }
public Collection<Text> getSplits(String tableName) throws TableNotFoundException, AccumuloSecurityException, AccumuloException { return this.connector.tableOperations().listSplits(tableName); } public SortedSet<String> getTableList() {
public static Range pickRange(TableOperations tops, String table, Random r) throws TableNotFoundException, AccumuloSecurityException, AccumuloException { ArrayList<Text> splits = Lists.newArrayList(tops.listSplits(table)); if (splits.isEmpty()) { return new Range(); } else { int index = r.nextInt(splits.size()); Text endRow = splits.get(index); Text startRow = index == 0 ? null : splits.get(index - 1); return new Range(startRow, false, endRow, true); } }
private List<TabletInfo<T>> listSplits() throws TableNotFoundException, AccumuloSecurityException, AccumuloException { List<Text> splits = new ArrayList<>(env.getConnector().tableOperations().listSplits(env.getTable())); Collections.sort(splits); List<TabletInfo<T>> tablets = new ArrayList<>(splits.size() + 1); for (int i = 0; i < splits.size(); i++) { tablets .add(new TabletInfo<>(i == 0 ? null : splits.get(i - 1), splits.get(i), supplier.get())); } tablets.add(new TabletInfo<>(splits.size() == 0 ? null : splits.get(splits.size() - 1), null, supplier.get())); listSplitsTime = System.currentTimeMillis(); return tablets; }
public static byte[] serializeTableSplits(Environment env) { List<Bytes> splits; try { splits = env.getConnector().tableOperations().listSplits(env.getTable()).stream() .map(ByteUtil::toBytes).collect(Collectors.toList()); } catch (TableNotFoundException | AccumuloSecurityException | AccumuloException e) { throw new RuntimeException(e); } return serialize(splits); } }
public static byte[] serializeTableSplits(Environment env) { List<Bytes> splits; try { splits = env.getAccumuloClient().tableOperations().listSplits(env.getTable()).stream() .map(ByteUtil::toBytes).collect(Collectors.toList()); } catch (TableNotFoundException | AccumuloSecurityException | AccumuloException e) { throw new RuntimeException(e); } return serialize(splits); } }
@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> tableNames = (List<String>) state.get("tables"); String tableName = tableNames.get(rand.nextInt(tableNames.size())); try { Collection<Text> splits = conn.tableOperations().listSplits(tableName); log.debug("Table " + tableName + " had " + splits.size() + " splits"); } catch (TableNotFoundException e) { log.debug("listSplits " + tableName + " failed, doesnt exist"); } catch (AccumuloSecurityException ase) { log.debug("listSplits " + tableName + " failed, " + ase.getMessage()); } } }
private void sort(State state, Environment env, FileSystem fs, String tableName, String seqFile, String outputDir, String workDir, int maxSplits) throws Exception { PrintStream out = new PrintStream( new BufferedOutputStream(fs.create(new Path(workDir + "/splits.txt"))), false, UTF_8.name()); Connector conn = env.getConnector(); Collection<Text> splits = conn.tableOperations().listSplits(tableName, maxSplits); for (Text split : splits) out.println(Base64.encodeBase64String(TextUtil.getBytes(split))); out.close(); SortTool sortTool = new SortTool(seqFile, outputDir, workDir + "/splits.txt", splits); String[] args = new String[2]; args[0] = "-libjars"; args[1] = getMapReduceJars(); if (ToolRunner.run(CachedConfiguration.getInstance(), sortTool, args) != 0) { throw new Exception("Failed to run map/red verify"); } }
@Before public void saveMetadataSplits() throws Exception { if (ClusterType.STANDALONE == getClusterType()) { Connector conn = getConnector(); Collection<Text> splits = conn.tableOperations().listSplits(MetadataTable.NAME); // We expect a single split if (!splits.equals(Arrays.asList(new Text("~")))) { log.info("Existing splits on metadata table. Saving them, and applying" + " single original split of '~'"); metadataSplits = splits; conn.tableOperations().merge(MetadataTable.NAME, null, null); conn.tableOperations().addSplits(MetadataTable.NAME, new TreeSet<>(Collections.singleton(new Text("~")))); } } }
private static List<TableRange> getRanges(Environment env) throws TableNotFoundException, AccumuloSecurityException, AccumuloException { List<TableRange> ranges = TableRange.fromTexts(env.getAccumuloClient().tableOperations().listSplits(env.getTable())); Collections.shuffle(ranges); return ranges; }
@Override public void visit(State state, Environment env, Properties props) throws Exception { String indexTableName = (String) state.get("indexTableName"); Collection<Text> splits = env.getConnector().tableOperations().listSplits(indexTableName); SortedSet<Text> splitSet = new TreeSet<>(splits); log.debug("merging " + indexTableName); env.getConnector().tableOperations().merge(indexTableName, null, null); org.apache.accumulo.core.util.Merge merge = new org.apache.accumulo.core.util.Merge(); merge.mergomatic(env.getConnector(), indexTableName, null, null, 256 * 1024 * 1024, true); splits = env.getConnector().tableOperations().listSplits(indexTableName); if (splits.size() > splitSet.size()) { // throw an excpetion so that test will die an no further changes to table will occur... // this way table is left as is for debugging. throw new Exception( "There are more tablets after a merge: " + splits.size() + " was " + splitSet.size()); } }
private Iterable<Range> listTableSplits(String tableName) { try { return splitsIterableToRangeIterable(getConnector().tableOperations().listSplits(tableName)); } catch (Exception ex) { throw new VertexiumException("Could not get splits for: " + tableName, ex); } }
private Iterable<Range> listTableSplits(String tableName) { try { return splitsIterableToRangeIterable(getConnector().tableOperations().listSplits(tableName)); } catch (Exception ex) { throw new VertexiumException("Could not get splits for: " + tableName, ex); } }
@Test public void test() throws Exception { Connector c = getConnector(); assertEquals(1, c.tableOperations().listSplits(MetadataTable.NAME).size()); c.tableOperations().setProperty(MetadataTable.NAME, Property.TABLE_SPLIT_THRESHOLD.getKey(), "500"); for (int i = 0; i < 10; i++) { c.tableOperations().create("table" + i); c.tableOperations().flush(MetadataTable.NAME, null, null, true); } sleepUninterruptibly(10, TimeUnit.SECONDS); assertTrue(c.tableOperations().listSplits(MetadataTable.NAME).size() > 2); } }
@Test public void merge() throws Exception { Connector c = getConnector(); String tableName = getUniqueNames(1)[0]; c.tableOperations().create(tableName); c.tableOperations().addSplits(tableName, splits("a b c d e f g h i j k".split(" "))); BatchWriter bw = c.createBatchWriter(tableName, null); for (String row : "a b c d e f g h i j k".split(" ")) { Mutation m = new Mutation(row); m.put("cf", "cq", "value"); bw.addMutation(m); } bw.close(); c.tableOperations().flush(tableName, null, null, true); c.tableOperations().merge(tableName, new Text("c1"), new Text("f1")); assertEquals(8, c.tableOperations().listSplits(tableName).size()); }