Package org.apache.accumulo.core.client

Examples of org.apache.accumulo.core.client.BatchWriter


   * This method attempts to do its best to remove files from the filesystem that have been confirmed for deletion.
   */
  private void deleteFiles(SortedSet<String> confirmedDeletes) {
    // create a batchwriter to remove the delete flags for successful
    // deletes; Need separate writer for the root tablet.
    BatchWriter writer = null;
    BatchWriter rootWriter = null;
    if (!offline) {
      Connector c;
      try {
        c = instance.getConnector(SecurityConstants.SYSTEM_PRINCIPAL, SecurityConstants.getSystemToken());
        writer = c.createBatchWriter(Constants.METADATA_TABLE_NAME, new BatchWriterConfig());
        rootWriter = c.createBatchWriter(Constants.METADATA_TABLE_NAME, new BatchWriterConfig());
      } catch (Exception e) {
        log.error("Unable to create writer to remove file from the !METADATA table", e);
      }
    }
    // when deleting a dir and all files in that dir, only need to delete the dir
    // the dir will sort right before the files... so remove the files in this case
    // to minimize namenode ops
    Iterator<String> cdIter = confirmedDeletes.iterator();
    String lastDir = null;
    while (cdIter.hasNext()) {
      String delete = cdIter.next();
      if (isDir(delete)) {
        lastDir = delete;
      } else if (lastDir != null) {
        if (delete.startsWith(lastDir)) {
          log.debug("Ignoring " + delete + " because " + lastDir + " exist");
          try {
            putMarkerDeleteMutation(delete, writer, rootWriter);
          } catch (MutationsRejectedException e) {
            throw new RuntimeException(e);
          }
          cdIter.remove();
        } else {
          lastDir = null;
        }
       
      }
    }
   
    final BatchWriter finalWriter = writer;
    final BatchWriter finalRootWriter = rootWriter;
   
    ExecutorService deleteThreadPool = Executors.newFixedThreadPool(numDeleteThreads, new NamingThreadFactory("deleting"));
   
    for (final String delete : confirmedDeletes) {
     
View Full Code Here


  public void testDeleteRowsWithNullKeys() throws Exception {
    Instance instance = new MockInstance("rows");
    Connector connector = instance.getConnector("user", new PasswordToken("foo"));
    TableOperations to = connector.tableOperations();
    to.create("test2");
    BatchWriter bw = connector.createBatchWriter("test2", new BatchWriterConfig());
    for (int r = 0; r < 30; r++) {
      Mutation m = new Mutation(Integer.toString(r));
      for (int c = 0; c < 5; c++) {
        m.put(new Text("cf"), new Text(Integer.toString(c)), new Value(Integer.toString(c).getBytes()));
      }
      bw.addMutation(m);
    }
    bw.flush();

    // test null end
    // will remove rows 4 through 9 (6 * 5 = 30 entries)
    to.deleteRows("test2", new Text("30"), null);
    Scanner s = connector.createScanner("test2", Constants.NO_AUTHS);
View Full Code Here

  @Test
  public void testCMod() throws Exception {
    // test writing to a table that the is being scanned
    Connector c = new MockConnector("root", new MockInstance());
    c.tableOperations().create("test");
    BatchWriter bw = c.createBatchWriter("test", new BatchWriterConfig());
   
    for (int i = 0; i < 10; i++) {
      Mutation m1 = new Mutation("r" + i);
      m1.put("cf1", "cq1", 1, "v" + i);
      bw.addMutation(m1);
    }
   
    bw.flush();
   
    int count = 10;
   
    Scanner scanner = c.createScanner("test", Constants.NO_AUTHS);
    for (Entry<Key,Value> entry : scanner) {
      Key key = entry.getKey();
      Mutation m = new Mutation(key.getRow());
      m.put(key.getColumnFamily().toString(), key.getColumnQualifier().toString(), key.getTimestamp() + 1, "v" + (count));
      count++;
      bw.addMutation(m);
    }
   
    bw.flush();
   
    count = 10;
   
    for (Entry<Key,Value> entry : scanner) {
      assertEquals(entry.getValue().toString(), "v" + (count++));
View Full Code Here

    c.tableOperations().create("a");
    c.tableOperations().create("b");
    MultiTableBatchWriter bw = c.createMultiTableBatchWriter(new BatchWriterConfig());
    Mutation m1 = new Mutation("r1");
    m1.put("cf1", "cq1", 1, "v1");
    BatchWriter b = bw.getBatchWriter("a");
    b.addMutation(m1);
    b.flush();
    b = bw.getBatchWriter("b");
    b.addMutation(m1);
    b.flush();
   
    Scanner scanner = c.createScanner("a", Constants.NO_AUTHS);
    int count = 0;
    for (@SuppressWarnings("unused")
    Entry<Key,Value> entry : scanner) {
View Full Code Here

 
  @Test
  public void testUpdate() throws Exception {
    Connector c = new MockConnector("root", new MockInstance());
    c.tableOperations().create("test");
    BatchWriter bw = c.createBatchWriter("test", new BatchWriterConfig());
   
    for (int i = 0; i < 10; i++) {
      Mutation m = new Mutation("r1");
      m.put("cf1", "cq1", "" + i);
      bw.addMutation(m);
    }
   
    bw.close();
   
    Scanner scanner = c.createScanner("test", Constants.NO_AUTHS);
   
    Entry<Key,Value> entry = scanner.iterator().next();
   
View Full Code Here

      if (s.parentId == Span.ROOT_SPAN_ID) {
        timeMutation = new Mutation(new Text("start:" + startString));
        put(timeMutation, "id", idString, transport.get(), transport.len());
      }
      try {
        final BatchWriter writer = TraceServer.this.writer.get();
        /* Check for null, because we expect spans to come in much faster than flush calls.
           In the case of failure, we'd rather avoid logging tons of NPEs.
         */
        if (null == writer) {
          log.warn("writer is not ready; discarding span.");
          return;
        }
        writer.addMutation(spanMutation);
        writer.addMutation(indexMutation);
        if (timeMutation != null)
          writer.addMutation(timeMutation);
      } catch (MutationsRejectedException exception) {
        log.warn("Unable to write mutation to table; discarding span. set log level to DEBUG for span information and stacktrace. cause: " + exception);
        if (log.isDebugEnabled()) {
          log.debug("discarded span due to rejection of mutation: " + spanMutation, exception);
        }
View Full Code Here

  public void test1() throws Exception {
    MockInstance instance = new MockInstance("rft1");
    Connector conn = instance.getConnector("", new PasswordToken(""));

    conn.tableOperations().create("table1");
    BatchWriter bw = conn.createBatchWriter("table1", new BatchWriterConfig());

    for (Mutation m : createMutations()) {
      bw.addMutation(m);
    }
    IteratorSetting is = new IteratorSetting(40, SummingRowFilter.class);
    conn.tableOperations().attachIterator("table1", is);

    Scanner scanner = conn.createScanner("table1", Constants.NO_AUTHS);
View Full Code Here

  public void testChainedRowFilters() throws Exception {
    MockInstance instance = new MockInstance("rft1");
    Connector conn = instance.getConnector("", new PasswordToken(""));

    conn.tableOperations().create("chained_row_filters");
    BatchWriter bw = conn.createBatchWriter("chained_row_filters", new BatchWriterConfig());
    for (Mutation m : createMutations()) {
      bw.addMutation(m);
    }
    conn.tableOperations().attachIterator("chained_row_filters", new IteratorSetting(40, "trueFilter1", TrueFilter.class));
    conn.tableOperations().attachIterator("chained_row_filters", new IteratorSetting(41, "trueFilter2", TrueFilter.class));
    Scanner scanner = conn.createScanner("chained_row_filters", Constants.NO_AUTHS);
    assertEquals(new HashSet<String>(Arrays.asList("0", "1", "2", "3", "4")), getRows(scanner));
View Full Code Here

  public void testFilterConjunction() throws Exception {
    MockInstance instance = new MockInstance("rft1");
    Connector conn = instance.getConnector("", new PasswordToken(""));

    conn.tableOperations().create("filter_conjunction");
    BatchWriter bw = conn.createBatchWriter("filter_conjunction", new BatchWriterConfig());
    for (Mutation m : createMutations()) {
      bw.addMutation(m);
    }
    conn.tableOperations().attachIterator("filter_conjunction", new IteratorSetting(40, "rowZeroOrOne", RowZeroOrOneFilter.class));
    conn.tableOperations().attachIterator("filter_conjunction", new IteratorSetting(41, "rowOneOrTwo", RowOneOrTwoFilter.class));
    Scanner scanner = conn.createScanner("filter_conjunction", Constants.NO_AUTHS);
    assertEquals(new HashSet<String>(Arrays.asList("1")), getRows(scanner));
View Full Code Here

  }
 
  @Override
  public void delete() throws MutationsRejectedException, TableNotFoundException {
   
    BatchWriter writer = new MockBatchWriter(acc, tableName);
    try {
      Iterator<Entry<Key,Value>> iter = super.iterator();
      while (iter.hasNext()) {
        Entry<Key,Value> next = iter.next();
        Key k = next.getKey();
        Mutation m = new Mutation(k.getRow());
        m.putDelete(k.getColumnFamily(), k.getColumnQualifier(), new ColumnVisibility(k.getColumnVisibility()), k.getTimestamp());
        writer.addMutation(m);
      }
    } finally {
      writer.close();
    }
  }
View Full Code Here

TOP

Related Classes of org.apache.accumulo.core.client.BatchWriter

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.