Package org.apache.accumulo.core.data

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


        FileSKVIterator importIterator = FileOperations.getInstance()
            .openReader(importStatus.getPath().toString(), true, fs,
                fs.getConf(), AccumuloConfiguration.getDefaultConfiguration());
        while (importIterator.hasTop()) {
          Key key = importIterator.getTopKey();
          Value value = importIterator.getTopValue();
          if (setTime) {
            key.setTimestamp(time);
          }
          Mutation mutation = new Mutation(key.getRow());
          if (!key.isDeleted()) {
View Full Code Here


                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

  static class AddingIter extends WrappedIter {
   
    int amount = 1;
   
    public Value getTopValue() {
      Value val = super.getTopValue();
     
      int orig = Integer.parseInt(val.toString());
     
      return new Value(((orig + amount) + "").getBytes());
    }
View Full Code Here

    }
  }
 
  static class SquaringIter extends WrappedIter {
    public Value getTopValue() {
      Value val = super.getTopValue();
     
      int orig = Integer.parseInt(val.toString());
     
      return new Value(((orig * orig) + "").getBytes());
    }
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

    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
    MergeStats stats = scan(state, metaDataStateStore);
    MergeState newState = stats.nextMergeState(connector, state);
    Assert.assertEquals(MergeState.WAITING_FOR_OFFLINE, newState);
   
    // unassign the tablets
    BatchDeleter deleter = connector.createBatchDeleter("!METADATA", Constants.NO_AUTHS, 1000, new BatchWriterConfig());
    deleter.fetchColumnFamily(Constants.METADATA_CURRENT_LOCATION_COLUMN_FAMILY);
    deleter.setRanges(Collections.singletonList(new Range()));
    deleter.delete();
   
    // now we should be ready to merge but, we have an inconsistent !METADATA table
    stats = scan(state, metaDataStateStore);
    Assert.assertEquals(MergeState.WAITING_FOR_OFFLINE, stats.nextMergeState(connector, state));
   
    // finish the split
    KeyExtent tablet = new KeyExtent(tableId, new Text("p"), new Text("o"));
    m = tablet.getPrevRowUpdateMutation();
    Constants.METADATA_SPLIT_RATIO_COLUMN.put(m, new Value("0.5".getBytes()));
    update(connector, m);
    metaDataStateStore.setLocations(Collections.singletonList(new Assignment(tablet, state.someTServer)));
   
    // onos... there's a new tablet online
    stats = scan(state, metaDataStateStore);
    Assert.assertEquals(MergeState.WAITING_FOR_CHOPPED, stats.nextMergeState(connector, state));
   
    // chop it
    m = tablet.getPrevRowUpdateMutation();
    Constants.METADATA_CHOPPED_COLUMN.put(m, new Value("junk".getBytes()));
    update(connector, m);
   
    stats = scan(state, metaDataStateStore);
    Assert.assertEquals(MergeState.WAITING_FOR_OFFLINE, stats.nextMergeState(connector, state));
   
View Full Code Here

    } else {
      entries = new TreeMap<Key,Value>();
      Text rowName = extent.getMetadataEntry();
      for (Entry<Key,Value> entry : tabletsKeyValues.entrySet()) {
        if (entry.getKey().compareRow(rowName) == 0 && Constants.METADATA_TIME_COLUMN.hasColumns(entry.getKey())) {
          entries.put(new Key(entry.getKey()), new Value(entry.getValue()));
        }
      }
    }
   
    // log.debug("extent : "+extent+"   entries : "+entries);
View Full Code Here

         
          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();
      } else if (opts.mode.equals("verifyDeleted")) {
        Scanner s = connector.createScanner(opts.tableName, opts.auths);
        s.setBatchSize(scanOpts.scanBatchSize);
        Key startKey = new Key(encodeLong(opts.start), CF_BYTES, CQ_BYTES, new byte[0], Long.MAX_VALUE);
        Key stopKey = new Key(encodeLong(opts.start + opts.num - 1), CF_BYTES, CQ_BYTES, new byte[0], 0);
        s.setBatchSize(50000);
        s.setRange(new Range(startKey, stopKey));
       
        for (Entry<Key,Value> entry : s) {
          System.err.println("ERROR : saw entries in range that should be deleted ( first value : " + entry.getValue().toString() + ")");
          System.err.println("exiting...");
          System.exit(1);
        }
       
      } else if (opts.mode.equals("verify")) {
        long t1 = System.currentTimeMillis();
       
        Scanner s = connector.createScanner(opts.tableName, opts.auths);
        Key startKey = new Key(encodeLong(opts.start), CF_BYTES, CQ_BYTES, new byte[0], Long.MAX_VALUE);
        Key stopKey = new Key(encodeLong(opts.start + opts.num - 1), CF_BYTES, CQ_BYTES, new byte[0], 0);
        s.setBatchSize(scanOpts.scanBatchSize);
        s.setRange(new Range(startKey, stopKey));
       
        long i = opts.start;
       
        for (Entry<Key,Value> e : s) {
          Key k = e.getKey();
          Value v = e.getValue();
         
          // System.out.println("v = "+v);
         
          checkKeyValue(i, k, v);
         
          i++;
        }
       
        if (i != opts.start + opts.num) {
          System.err.println("ERROR : did not see expected number of rows, saw " + (i - opts.start) + " expected " + opts.num);
          System.err.println("exiting... ARGHHHHHH");
          System.exit(1);
         
        }
       
        long t2 = System.currentTimeMillis();
       
        System.out.printf("time : %9.2f secs%n", ((t2 - t1) / 1000.0));
        System.out.printf("rate : %9.2f entries/sec%n", opts.num / ((t2 - t1) / 1000.0));
       
      } else if (opts.mode.equals("randomLookups")) {
        int numLookups = 1000;
       
        Random r = new Random();
       
        long t1 = System.currentTimeMillis();
       
        for (int i = 0; i < numLookups; i++) {
          long row = ((r.nextLong() & 0x7fffffffffffffffl) % opts.num) + opts.start;
         
          Scanner s = connector.createScanner(opts.tableName, opts.auths);
          s.setBatchSize(scanOpts.scanBatchSize);
          Key startKey = new Key(encodeLong(row), CF_BYTES, CQ_BYTES, new byte[0], Long.MAX_VALUE);
          Key stopKey = new Key(encodeLong(row), CF_BYTES, CQ_BYTES, new byte[0], 0);
          s.setRange(new Range(startKey, stopKey));
         
          Iterator<Entry<Key,Value>> si = s.iterator();
         
          if (si.hasNext()) {
            Entry<Key,Value> e = si.next();
            Key k = e.getKey();
            Value v = e.getValue();
           
            checkKeyValue(row, k, v);
           
            if (si.hasNext()) {
              System.err.println("ERROR : lookup on " + row + " returned more than one result ");
View Full Code Here

       
        if (entry.getKey().compareRow(rowName) != 0) {
          break;
        }
       
        datafilesMetadata.put(new Key(entry.getKey()), new Value(entry.getValue()));
      }
     
      Iterator<Entry<Key,Value>> dfmdIter = datafilesMetadata.entrySet().iterator();
     
      while (dfmdIter.hasNext()) {
View Full Code Here

    // log.info("In nextBatch..");
   
    List<KVEntry> results = new ArrayList<KVEntry>();
    Key key = null;
   
    Value value;
    long resultSize = 0L;
    long resultBytes = 0L;
   
    long maxResultsSize = acuTableConf.getMemoryInBytes(Property.TABLE_SCAN_MAXMEM);
   
View Full Code Here

TOP

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

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.