Package org.apache.accumulo.core.data

Examples of org.apache.accumulo.core.data.Mutation


    // create a copy of mutation so that after this method returns the user
    // is free to reuse the mutation object, like calling readFields... this
    // is important for the case where a mutation is passed from map to reduce
    // to batch writer... the map reduce code will keep passing the same mutation
    // object into the reduce method
    m = new Mutation(m);
   
    totalMemUsed += m.estimatedMemoryUsed();
    mutations.addMutation(table, m);
    totalAdded++;
   
View Full Code Here


      return;
   
    HashMap<Text,ColumnVisibility> vizMap = new HashMap<Text,ColumnVisibility>();
   
    for (Map.Entry<ByteBuffer,List<ColumnUpdate>> entry : cells.entrySet()) {
      Mutation m = new Mutation(ByteBufferUtil.toBytes(entry.getKey()));
     
      for (ColumnUpdate update : entry.getValue()) {
        ColumnVisibility viz = EMPTY_VIS;
        if (update.isSetColVisibility()) {
          Text vizText = new Text(update.getColVisibility());
          viz = vizMap.get(vizText);
          if (viz == null) {
            vizMap.put(vizText, viz = new ColumnVisibility(vizText));
          }
        }
        byte[] value = new byte[0];
        if (update.isSetValue())
          value = update.getValue();
        if (update.isSetTimestamp()) {
          if (update.isSetDeleteCell()) {
            m.putDelete(update.getColFamily(), update.getColQualifier(), viz, update.getTimestamp());
          } else {
            m.put(new Text(update.getColFamily()), new Text(update.getColQualifier()), viz, update.getTimestamp(), new Value(value));
            }
        } else {
          if (update.isSetDeleteCell()) {
            m.putDelete(new Text(update.getColFamily()), new Text(update.getColQualifier()), viz);
          } else {
            m.put(new Text(update.getColFamily()), new Text(update.getColQualifier()), viz, new Value(value));
          }
        }
      }
      try {
        bwpe.writer.addMutation(m);
View Full Code Here

    for (int i = 0; i < NUM_ROWS; i++) {
     
      r.nextBytes(rowData);
      TestIngest.toPrintableChars(rowData);
     
      Mutation mut = new Mutation(new Text(rowData));
      mut.put(new Text(""), new Text(""), new Value(Integer.toString(i).getBytes(Constants.UTF8)));
      bw.addMutation(mut);
    }
   
    bw.close();
   
View Full Code Here

    if ((totalWrites % 10000) == 0) {
      log.debug("Total writes: " + totalWrites);
    }
    state.set("totalWrites", totalWrites);
   
    Mutation m = new Mutation(new Text(String.format("%010d", totalWrites)));
    m.put(new Text("cf"), new Text("cq"), new Value("val".getBytes(Constants.UTF8)));
    bw.addMutation(m);
  }
View Full Code Here

    getConnector().tableOperations().create("test");

    BatchWriter bw = getConnector().createBatchWriter("test", new BatchWriterConfig());

    Mutation m1 = new Mutation("r1");
    m1.put("cf1", "cq1", 1, "5");

    bw.addMutation(m1);

    bw.flush();

    Scanner scanner = getConnector().createScanner("test", new Authorizations());

    int count = 0;
    for (Entry<Key,Value> entry : scanner) {
      count++;
      if (!entry.getValue().toString().equals("5")) {
        throw new Exception("Unexpected value " + entry.getValue());
      }
    }

    if (count != 1) {
      throw new Exception("Unexpected count " + count);
    }

    if (countThreads() < 2) {
      printThreadNames();
      throw new Exception("Not seeing expected threads");
    }

    CleanUp.shutdownNow();

    Mutation m2 = new Mutation("r2");
    m2.put("cf1", "cq1", 1, "6");

    try {
      bw.addMutation(m1);
      bw.flush();
      throw new Exception("batch writer did not fail");
View Full Code Here

      }
      writeMutation(output, start, index);
    }
   
    public void writeMutation(Context output, int start, int end) throws IOException, InterruptedException {
      Mutation m = new Mutation(new Text(String.format("%010d", start)));
      m.put(new Text(String.format("%010d", end)), new Text(""), new Value(new byte[0]));
      output.write(null, m);
    }
View Full Code Here

    try {
      BatchWriter bw = conn.createBatchWriter(tableName, new BatchWriterConfig());
      try {
        int numRows = rand.nextInt(100000);
        for (int i = 0; i < numRows; i++) {
          Mutation m = new Mutation(String.format("%016x", (rand.nextLong() & 0x7fffffffffffffffl)));
          long val = (rand.nextLong() & 0x7fffffffffffffffl);
          for (int j = 0; j < 10; j++) {
            m.put("cf", "cq" + j, new Value(String.format("%016x", val).getBytes(Constants.UTF8)));
          }
         
          bw.addMutation(m);
        }
      } finally {
View Full Code Here

  public void run() throws Exception {
   
    BatchWriter bw = getConnector().createBatchWriter("foo", new BatchWriterConfig());
   
    for (int i = 0; i < 1000; i++) {
      Mutation m = new Mutation(new Text(String.format("%06d", i)));
      m.put(new Text("cf1"), new Text("cq1"), new Value(Integer.toString(1000 - i).getBytes(Constants.UTF8)));
      m.put(new Text("cf1"), new Text("cq2"), new Value(Integer.toString(i - 1000).getBytes(Constants.UTF8)));
     
      bw.addMutation(m);
    }
   
    bw.close();
View Full Code Here

  private void runLatencyTest() throws Exception {
    // should automatically flush after 3 seconds
    BatchWriter bw = getConnector().createBatchWriter("bwlt", new BatchWriterConfig().setMaxLatency(2000, TimeUnit.MILLISECONDS));
    Scanner scanner = getConnector().createScanner("bwlt", Constants.NO_AUTHS);
   
    Mutation m = new Mutation(new Text(String.format("r_%10d", 1)));
    m.put(new Text("cf"), new Text("cq"), new Value("1".getBytes(Constants.UTF8)));
    bw.addMutation(m);
   
    UtilWaitThread.sleep(1000);
   
    int count = 0;
View Full Code Here

   
    for (int i = 0; i < 4; i++) {
      for (int j = 0; j < NUM_TO_FLUSH; j++) {
        int row = i * NUM_TO_FLUSH + j;
       
        Mutation m = new Mutation(new Text(String.format("r_%10d", row)));
        m.put(new Text("cf"), new Text("cq"), new Value(("" + row).getBytes()));
        bw.addMutation(m);
      }
     
      bw.flush();
     
      // do a few random lookups into the data just flushed
     
      for (int k = 0; k < 10; k++) {
        int rowToLookup = r.nextInt(NUM_TO_FLUSH) + i * NUM_TO_FLUSH;
       
        scanner.setRange(new Range(new Text(String.format("r_%10d", rowToLookup))));
       
        Iterator<Entry<Key,Value>> iter = scanner.iterator();
       
        if (!iter.hasNext())
          throw new Exception(" row " + rowToLookup + " not found after flush");
       
        Entry<Key,Value> entry = iter.next();
       
        if (iter.hasNext())
          throw new Exception("Scanner returned too much");
       
        verifyEntry(rowToLookup, entry);
      }
     
      // scan all data just flushed
      scanner.setRange(new Range(new Text(String.format("r_%10d", i * NUM_TO_FLUSH)), true, new Text(String.format("r_%10d", (i + 1) * NUM_TO_FLUSH)), false));
      Iterator<Entry<Key,Value>> iter = scanner.iterator();
     
      for (int j = 0; j < NUM_TO_FLUSH; j++) {
        int row = i * NUM_TO_FLUSH + j;
       
        if (!iter.hasNext())
          throw new Exception("Scan stopped permaturely at " + row);
       
        Entry<Key,Value> entry = iter.next();
       
        verifyEntry(row, entry);
      }
     
      if (iter.hasNext())
        throw new Exception("Scanner returned too much");
     
    }
   
    bw.close();
   
    // test adding a mutation to a closed batch writer
    boolean caught = false;
    try {
      bw.addMutation(new Mutation(new Text("foobar")));
    } catch (IllegalStateException ise) {
      caught = true;
    }
   
    if (!caught) {
View Full Code Here

TOP

Related Classes of org.apache.accumulo.core.data.Mutation

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.