Package org.apache.accumulo.core.data

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


 
  @Override
  public void put(K key, T val) {

    try{
      Mutation m = new Mutation(new Text(toBytes(key)));
     
      Schema schema = val.getSchema();
      StateManager stateManager = val.getStateManager();
     
      Iterator<Field> iter = schema.getFields().iterator();
     
      int count = 0;
      for (int i = 0; iter.hasNext(); i++) {
        Field field = iter.next();
        if (!stateManager.isDirty(val, i)) {
          continue;
        }
       
        Object o = val.get(i);
        Pair<Text,Text> col = mapping.fieldMap.get(field.name());
 
        switch (field.schema().getType()) {
          case MAP:
            if (o instanceof StatefulMap) {
              StatefulMap map = (StatefulMap) o;
              Set<?> es = map.states().entrySet();
              for (Object entry : es) {
                Object mapKey = ((Entry) entry).getKey();
                State state = (State) ((Entry) entry).getValue();
 
                switch (state) {
                  case NEW:
                  case DIRTY:
                    m.put(col.getFirst(), new Text(toBytes(mapKey)), new Value(toBytes(map.get(mapKey))));
                    count++;
                    break;
                  case DELETED:
                    m.putDelete(col.getFirst(), new Text(toBytes(mapKey)));
                    count++;
                    break;
                }
               
              }
            } else {
              Map map = (Map) o;
              Set<?> es = map.entrySet();
              for (Object entry : es) {
                Object mapKey = ((Entry) entry).getKey();
                Object mapVal = ((Entry) entry).getValue();
                m.put(col.getFirst(), new Text(toBytes(mapKey)), new Value(toBytes(mapVal)));
                count++;
              }
            }
            break;
          case ARRAY:
            GenericArray array = (GenericArray) o;
            int j = 0;
            for (Object item : array) {
              m.put(col.getFirst(), new Text(toBytes(j++)), new Value(toBytes(item)));
              count++;
            }
            break;
          case RECORD:
            SpecificDatumWriter writer = new SpecificDatumWriter(field.schema());
            ByteArrayOutputStream os = new ByteArrayOutputStream();
            BinaryEncoder encoder = new BinaryEncoder(os);
            writer.write(o, encoder);
            encoder.flush();
            m.put(col.getFirst(), col.getSecond(), new Value(os.toByteArray()));
            break;
          default:
            m.put(col.getFirst(), col.getSecond(), new Value(toBytes(o)));
            count++;
        }
 
      }
     
View Full Code Here


     
      long count = 0;

      while (iterator.hasNext()) {
        Iterator<Entry<Key,Value>> row = iterator.next();
        Mutation m = null;
        while (row.hasNext()) {
          Entry<Key,Value> entry = row.next();
          Key key = entry.getKey();
          if (m == null)
            m = new Mutation(key.getRow());
          // TODO optimize to avoid continually creating column vis? prob does not matter for empty
          m.putDelete(key.getColumnFamily(), key.getColumnQualifier(), new ColumnVisibility(key.getColumnVisibility()), key.getTimestamp());
        }
        getBatchWriter().addMutation(m);
        count++;
      }
     
View Full Code Here

   
    for (int i = 0; i < 100000; ++i) {
      final Text emptyText = new Text("");
      Text row = new Text(String.format("%s/%020d/%s", Constants.METADATA_DELETE_FLAG_PREFIX, i,
          "aaaaaaaaaabbbbbbbbbbccccccccccddddddddddeeeeeeeeeeffffffffffgggggggggghhhhhhhhhhiiiiiiiiiijjjjjjjjjj"));
      Mutation delFlag = new Mutation(row);
      delFlag.put(emptyText, emptyText, new Value(new byte[] {}));
      bw.addMutation(delFlag);
    }
    bw.close();
  }
View Full Code Here

    // create metadata for a table "t" with the splits above
    Text tableId = new Text("t");
    Text pr = null;
    for (String s : splits) {
      Text split = new Text(s);
      Mutation prevRow = KeyExtent.getPrevRowUpdateMutation(new KeyExtent(tableId, split, pr));
      prevRow.put(Constants.METADATA_CURRENT_LOCATION_COLUMN_FAMILY, new Text("123456"), new Value("127.0.0.1:1234".getBytes()));
      Constants.METADATA_CHOPPED_COLUMN.put(prevRow, new Value("junk".getBytes()));
      bw.addMutation(prevRow);
      pr = split;
    }
    // Add the default tablet
    Mutation defaultTablet = KeyExtent.getPrevRowUpdateMutation(new KeyExtent(tableId, null, pr));
    defaultTablet.put(Constants.METADATA_CURRENT_LOCATION_COLUMN_FAMILY, new Text("123456"), new Value("127.0.0.1:1234".getBytes()));
    bw.addMutation(defaultTablet);
    bw.close();
   
    // Read out the TabletLocationStates
    MockCurrentState state = new MockCurrentState(new MergeInfo(new KeyExtent(tableId, new Text("p"), new Text("e")), MergeInfo.Operation.MERGE));
    TCredentials auths = CredentialHelper.create("root", new PasswordToken(new byte[0]), "instance");
   
    // Verify the tablet state: hosted, and count
    MetaDataStateStore metaDataStateStore = new MetaDataStateStore(instance, auths, state);
    int count = 0;
    for (TabletLocationState tss : metaDataStateStore) {
      Assert.assertEquals(TabletState.HOSTED, tss.getState(state.onlineTabletServers()));
      count++;
    }
    Assert.assertEquals(splits.length + 1, count);
   
    // Create the hole
    // Split the tablet at one end of the range
    Mutation m = new KeyExtent(tableId, new Text("t"), new Text("p")).getPrevRowUpdateMutation();
    Constants.METADATA_SPLIT_RATIO_COLUMN.put(m, new Value("0.5".getBytes()));
    Constants.METADATA_OLD_PREV_ROW_COLUMN.put(m, KeyExtent.encodePrevEndRow(new Text("o")));
    update(connector, m);
   
    // do the state check
View Full Code Here

       
        for (long i = 0; i < opts.num; i++) {
          byte[] row = encodeLong(i + opts.start);
          String value = "" + (i + opts.start);
         
          Mutation m = new Mutation(new Text(row));
          if (delete) {
            m.putDelete(CF, CQ);
          } else {
            m.put(CF, CQ, new Value(value.getBytes(Constants.UTF8)));
          }
          bw.addMutation(m);
        }
       
        bw.close();
View Full Code Here

        throw new RuntimeException(e);
      }
     
      // populate
      for (int i = 0; i < opts.count; i++) {
        Mutation m = new Mutation(new Text(String.format("%05d", i)));
        m.put(new Text("col" + Integer.toString((i % 3) + 1)), new Text("qual"), new Value("junk".getBytes(Constants.UTF8)));
        b.getBatchWriter(tableNames.get(i % tableNames.size())).addMutation(m);
      }
      try {
        b.close();
      } catch (MutationsRejectedException e) {
View Full Code Here

    Instance instance = new MockInstance();
    Connector conn = instance.getConnector("root", new PasswordToken(new byte[0]));

    conn.tableOperations().create(table);
    BatchWriter bw = conn.createBatchWriter(table, new BatchWriterConfig());
    Mutation m = new Mutation(ball);
    m.put(new byte[0], new byte[0], new byte[0]);
    bw.addMutation(m);
    bw.close();

    IteratorSetting is = new IteratorSetting(5, RegExFilter.class);
    RegExFilter.setRegexs(is, s2, null, null, null, true, true);
View Full Code Here

 
  private static final byte ROW_PREFIX[] = new byte[] {'r'};
  private static final byte COL_PREFIX[] = new byte[] {'c'};
 
  static Mutation nm(int r) {
    return new Mutation(new Text(FastFormat.toZeroPaddedString(r, 6, 10, ROW_PREFIX)));
  }
View Full Code Here

 
  private static void populate(int start, int numRows, int numCols, NativeMap nm) {
    long t1 = System.currentTimeMillis();
    int mc = 1;
    for (int i = 0; i < numRows; i++) {
      Mutation m = nm(i + start);
      for (int j = 0; j < numCols; j++) {
        Value val = new Value("test".getBytes(Constants.UTF8));
        pc(m, j, val);
      }
      nm.mutate(m, mc++);
View Full Code Here

          log.warn("WALog entry for root tablet did not exist " + unusedWalLogs);
      }
      return;
    }

    Mutation m = new Mutation(extent.getMetadataEntry());

    if (dfv.getNumEntries() > 0) {
      m.put(Constants.METADATA_DATAFILE_COLUMN_FAMILY, new Text(path), new Value(dfv.encode()));
      Constants.METADATA_TIME_COLUMN.put(m, new Value(time.getBytes(Constants.UTF8)));
      // stuff in this location
      TServerInstance self = getTServerInstance(address, zooLock);
      self.putLastLocation(m);
      // erase the old location
      if (lastLocation != null && !lastLocation.equals(self))
        lastLocation.clearLastLocation(m);
    }
    if (unusedWalLogs != null) {
      for (String entry : unusedWalLogs) {
        m.putDelete(Constants.METADATA_LOG_COLUMN_FAMILY, new Text(entry));
      }
    }

    for (String scanFile : filesInUseByScans)
      m.put(Constants.METADATA_SCANFILE_COLUMN_FAMILY, new Text(scanFile), new Value(new byte[0]));
   
    if (mergeFile != null)
      m.putDelete(Constants.METADATA_DATAFILE_COLUMN_FAMILY, new Text(mergeFile));
   
    Constants.METADATA_FLUSH_COLUMN.put(m, new Value(Long.toString(flushId).getBytes(Constants.UTF8)));
   
    update(credentials, zooLock, m);
View Full Code Here

TOP

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

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.