Package org.apache.accumulo.core.data

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


    int numRows = 1 << 18;
   
    BatchWriter bw = getConnector().createBatchWriter("bss", new BatchWriterConfig());
   
    for (int i = 0; i < numRows; i++) {
      Mutation m = new Mutation(new Text(String.format("%09x", i)));
      m.put(new Text("cf1"), new Text("cq1"), new Value(String.format("%016x", numRows - i).getBytes(Constants.UTF8)));
      bw.addMutation(m);
    }
   
    bw.close();
   
View Full Code Here


 
  @Override
  public void run() throws Exception {
    BatchWriter bw = getConnector().createBatchWriter("cct", new BatchWriterConfig());
    for (int i = 0; i < 50; i++) {
      Mutation m = new Mutation(new Text(String.format("%06d", i)));
      m.put(new Text("cf1"), new Text("cq1"), new Value("foo".getBytes(Constants.UTF8)));
      bw.addMutation(m);
    }
   
    bw.flush();
   
    ScanTask st0 = new ScanTask(getConnector(), 300);
    st0.start();
   
    ScanTask st1 = new ScanTask(getConnector(), 100);
    st1.start();
   
    UtilWaitThread.sleep(50);
    getConnector().tableOperations().flush("cct", null, null, true);
   
    for (int i = 0; i < 50; i++) {
      Mutation m = new Mutation(new Text(String.format("%06d", i)));
      m.put(new Text("cf1"), new Text("cq1"), new Value("foo".getBytes(Constants.UTF8)));
      bw.addMutation(m);
    }
   
    bw.flush();
   
View Full Code Here

   
    BatchWriter imagesBW = mtbw.getBatchWriter(state.getString("imageTableName"));
    BatchWriter indexBW = mtbw.getBatchWriter(state.getString("indexTableName"));
   
    String uuid = UUID.randomUUID().toString();
    Mutation m = new Mutation(new Text(uuid));
   
    // create a fake image between 4KB and 1MB
    int maxSize = Integer.parseInt(props.getProperty("maxSize"));
    int minSize = Integer.parseInt(props.getProperty("minSize"));
   
    Random rand = new Random();
    int numBytes = rand.nextInt((maxSize - minSize)) + minSize;
    byte[] imageBytes = new byte[numBytes];
    rand.nextBytes(imageBytes);
    m.put(CONTENT_COLUMN_FAMILY, IMAGE_COLUMN_QUALIFIER, new Value(imageBytes));
   
    // store size
    m.put(META_COLUMN_FAMILY, new Text("size"), new Value(String.format("%d", numBytes).getBytes(Constants.UTF8)));
   
    // store hash
    MessageDigest alg = MessageDigest.getInstance("SHA-1");
    alg.update(imageBytes);
    byte[] hash = alg.digest();
    m.put(META_COLUMN_FAMILY, SHA1_COLUMN_QUALIFIER, new Value(hash));
   
    // update write counts
    state.set("numWrites", state.getLong("numWrites") + 1);
    Long totalWrites = state.getLong("totalWrites") + 1;
    state.set("totalWrites", totalWrites);
   
    // set count
    m.put(META_COLUMN_FAMILY, COUNT_COLUMN_QUALIFIER, new Value(String.format("%d", totalWrites).getBytes(Constants.UTF8)));
   
    // add mutation
    imagesBW.addMutation(m);
   
    // now add mutation to index
    Text row = new Text(hash);
    m = new Mutation(row);
    m.put(META_COLUMN_FAMILY, UUID_COLUMN_QUALIFIER, new Value(uuid.getBytes(Constants.UTF8)));
   
    indexBW.addMutation(m);
   
    Text lastRow = (Text) state.get("lastIndexRow");
    if (lastRow.compareTo(row) < 0) {
View Full Code Here

        TabletServer.this.resourceManager.waitUntilCommitsAreEnabled();
     
      long opid = writeTracker.startWrite(TabletType.type(keyExtent));
     
      try {
        Mutation mutation = new ServerMutation(tmutation);
        List<Mutation> mutations = Collections.singletonList(mutation);
       
        Span prep = Trace.start("prep");
        CommitSession cs = tablet.prepareMutationsForCommit(new TservConstraintEnv(security, credentials), mutations);
        prep.stop();
View Full Code Here

      for (Entry<Key, Value> entry : all.entrySet()) {
        TServerInstance alive = tserverSet.find(entry.getValue().toString());
        if (alive == null) {
          Master.log.info("Removing entry " + entry);
          BatchWriter bw = getConnector().createBatchWriter(Constants.METADATA_TABLE_NAME, new BatchWriterConfig());
          Mutation m = new Mutation(entry.getKey().getRow());
          m.putDelete(entry.getKey().getColumnFamily(), entry.getKey().getColumnQualifier());
          bw.addMutation(m);
          bw.close();
          return;
        }
      }
View Full Code Here

       
        if (followingTablet != null) {
          log.debug("Updating prevRow of " + followingTablet + " to " + range.getPrevEndRow());
          bw = conn.createBatchWriter(Constants.METADATA_TABLE_NAME, new BatchWriterConfig());
          try {
            Mutation m = new Mutation(followingTablet.getMetadataEntry());
            Constants.METADATA_PREV_ROW_COLUMN.put(m, KeyExtent.encodePrevEndRow(range.getPrevEndRow()));
            Constants.METADATA_CHOPPED_COLUMN.putDelete(m);
            bw.addMutation(m);
            bw.flush();
          } finally {
View Full Code Here

        scanner.setRange(scanRange);
        Constants.METADATA_PREV_ROW_COLUMN.fetch(scanner);
        Constants.METADATA_TIME_COLUMN.fetch(scanner);
        Constants.METADATA_DIRECTORY_COLUMN.fetch(scanner);
        scanner.fetchColumnFamily(Constants.METADATA_DATAFILE_COLUMN_FAMILY);
        Mutation m = new Mutation(stopRow);
        String maxLogicalTime = null;
        for (Entry<Key,Value> entry : scanner) {
          Key key = entry.getKey();
          Value value = entry.getValue();
          if (key.getColumnFamily().equals(Constants.METADATA_DATAFILE_COLUMN_FAMILY)) {
            m.put(key.getColumnFamily(), key.getColumnQualifier(), value);
            fileCount++;
          } else if (Constants.METADATA_PREV_ROW_COLUMN.hasColumns(key) && firstPrevRowValue == null) {
            log.debug("prevRow entry for lowest tablet is " + value);
            firstPrevRowValue = new Value(value);
          } else if (Constants.METADATA_TIME_COLUMN.hasColumns(key)) {
            maxLogicalTime = TabletTime.maxMetadataTime(maxLogicalTime, value.toString());
          } else if (Constants.METADATA_DIRECTORY_COLUMN.hasColumns(key)) {
            if (!range.isMeta())
              bw.addMutation(MetadataTable.createDeleteMutation(range.getTableId().toString(), entry.getValue().toString()));
          }
        }
       
        // read the logical time from the last tablet in the merge range, it is not included in
        // the loop above
        scanner = conn.createScanner(Constants.METADATA_TABLE_NAME, Constants.NO_AUTHS);
        Range last = new Range(stopRow);
        if (range.isMeta())
          last = last.clip(Constants.METADATA_ROOT_TABLET_KEYSPACE);
        scanner.setRange(last);
        Constants.METADATA_TIME_COLUMN.fetch(scanner);
        for (Entry<Key,Value> entry : scanner) {
          if (Constants.METADATA_TIME_COLUMN.hasColumns(entry.getKey())) {
            maxLogicalTime = TabletTime.maxMetadataTime(maxLogicalTime, entry.getValue().toString());
          }
        }
       
        if (maxLogicalTime != null)
          Constants.METADATA_TIME_COLUMN.put(m, new Value(maxLogicalTime.getBytes(Constants.UTF8)));
       
        if (!m.getUpdates().isEmpty()) {
          bw.addMutation(m);
        }
       
        bw.flush();
       
        log.debug("Moved " + fileCount + " files to " + stop);
       
        if (firstPrevRowValue == null) {
          log.debug("tablet already merged");
          return;
        }
       
        stop.setPrevEndRow(KeyExtent.decodePrevEndRow(firstPrevRowValue));
        Mutation updatePrevRow = stop.getPrevRowUpdateMutation();
        log.debug("Setting the prevRow for last tablet: " + stop);
        bw.addMutation(updatePrevRow);
        bw.flush();
       
        deleteTablets(scanRange, bw, conn);
       
        // Clean-up the last chopped marker
        m = new Mutation(stopRow);
        Constants.METADATA_CHOPPED_COLUMN.putDelete(m);
        bw.addMutation(m);
        bw.flush();
       
      } catch (Exception ex) {
View Full Code Here

      }
    }
   
    private void deleteTablets(Range scanRange, BatchWriter bw, Connector conn) throws TableNotFoundException, MutationsRejectedException {
      Scanner scanner;
      Mutation m;
      // Delete everything in the other tablets
      // group all deletes into tablet into one mutation, this makes tablets
      // either disappear entirely or not all.. this is important for the case
      // where the process terminates in the loop below...
      scanner = conn.createScanner(Constants.METADATA_TABLE_NAME, Constants.NO_AUTHS);
      log.debug("Deleting range " + scanRange);
      scanner.setRange(scanRange);
      RowIterator rowIter = new RowIterator(scanner);
      while (rowIter.hasNext()) {
        Iterator<Entry<Key,Value>> row = rowIter.next();
        m = null;
        while (row.hasNext()) {
          Entry<Key,Value> entry = row.next();
          Key key = entry.getKey();
         
          if (m == null)
            m = new Mutation(key.getRow());
         
          m.putDelete(key.getColumnFamily(), key.getColumnQualifier());
          log.debug("deleting entry " + key);
        }
        bw.addMutation(m);
      }
     
View Full Code Here

      if (!getConnector().tableOperations().exists(TEST_TABLE)) {
        // create the test table
        getConnector().tableOperations().create(TEST_TABLE);
        // put in some initial data
        BatchWriter writer = getConnector().createBatchWriter(TEST_TABLE, new BatchWriterConfig());
        Mutation m = new Mutation(new Text("row"));
        m.put(new Text("cf"), new Text("cq"), new Value("val".getBytes(Constants.UTF8)));
        writer.addMutation(m);
        writer.close();
       
        // verify proper permissions for creator and test user
        verifyHasOnlyTheseTablePermissions(getConnector(), getConnector().whoami(), TEST_TABLE, TablePermission.values());
View Full Code Here

   
    private static void testMissingTablePermission(Connector root_conn, Connector test_user_conn, TablePermission perm) throws AccumuloException,
        AccumuloSecurityException, TableNotFoundException {
      Scanner scanner;
      BatchWriter writer;
      Mutation m;
      log.debug("Confirming that the lack of the " + perm + " permission properly restricts the user");
     
      // test permission prior to granting it
      switch (perm) {
        case READ:
          try {
            scanner = test_user_conn.createScanner(TEST_TABLE, Constants.NO_AUTHS);
            int i = 0;
            for (Entry<Key,Value> entry : scanner)
              i += 1 + entry.getKey().getRowData().length();
            if (i != 0)
              throw new IllegalStateException("Should NOT be able to read from the table");
          } catch (RuntimeException e) {
            AccumuloSecurityException se = (AccumuloSecurityException) e.getCause();
            if (se.getSecurityErrorCode() != SecurityErrorCode.PERMISSION_DENIED)
              throw se;
          }
          break;
        case WRITE:
          try {
            writer = test_user_conn.createBatchWriter(TEST_TABLE, new BatchWriterConfig());
            m = new Mutation(new Text("row"));
            m.put(new Text("a"), new Text("b"), new Value("c".getBytes(Constants.UTF8)));
            writer.addMutation(m);
            try {
              writer.close();
            } catch (MutationsRejectedException e1) {
              if (e1.getAuthorizationFailuresMap().size() > 0)
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.