Java Code Examples for org.apache.accumulo.core.data.Key#setTimestamp()

The following examples show how to use org.apache.accumulo.core.data.Key#setTimestamp() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: buggyMockTable.java    From coming with MIT License 6 votes vote down vote up
synchronized void addMutation(Mutation m) {
  long now = System.currentTimeMillis();
  mutationCount++;
  for (ColumnUpdate u : m.getUpdates()) {
    Key key = new Key(m.getRow(), 0, m.getRow().length, u.getColumnFamily(), 0, u.getColumnFamily().length, u.getColumnQualifier(), 0,
        u.getColumnQualifier().length, u.getColumnVisibility(), 0, u.getColumnVisibility().length, u.getTimestamp());
    if (u.isDeleted())
      key.setDeleted(true);
    if (!u.hasTimestamp())
      if (timeType.equals(TimeType.LOGICAL))
        key.setTimestamp(mutationCount);
      else
        key.setTimestamp(now);
    
    table.put(new MockMemKey(key, mutationCount), new Value(u.getValue()));
  }
}
 
Example 2
Source File: humanMockTable.java    From coming with MIT License 6 votes vote down vote up
synchronized void addMutation(Mutation m) {
  long now = System.currentTimeMillis();
  mutationCount++;
  for (ColumnUpdate u : m.getUpdates()) {
    Key key = new Key(m.getRow(), 0, m.getRow().length, u.getColumnFamily(), 0, u.getColumnFamily().length, u.getColumnQualifier(), 0,
        u.getColumnQualifier().length, u.getColumnVisibility(), 0, u.getColumnVisibility().length, u.getTimestamp());
    if (u.isDeleted())
      key.setDeleted(true);
    if (!u.hasTimestamp())
      if (timeType.equals(TimeType.LOGICAL))
        key.setTimestamp(mutationCount);
      else
        key.setTimestamp(now);
    
    table.put(new MockMemKey(key, mutationCount), new Value(u.getValue()));
  }
}
 
Example 3
Source File: TimestampSkippingIterator.java    From fluo with Apache License 2.0 6 votes vote down vote up
public void skipToTimestamp(Key curCol, long timestamp) throws IOException {
  source.next();
  int count = 0;
  while (source.hasTop()
      && curCol.equals(source.getTopKey(), PartialKey.ROW_COLFAM_COLQUAL_COLVIS)
      && timestamp < source.getTopKey().getTimestamp()) {
    if (count == 10) {
      // seek to prefix
      Key seekKey = new Key(curCol);
      seekKey.setTimestamp(timestamp);
      Range newRange = new Range(seekKey, true, range.getEndKey(), range.isEndKeyInclusive());
      seek(newRange);
      break;
    }
    source.next();
    count++;
  }
}
 
Example 4
Source File: ParallelSnapshotScanner.java    From fluo with Apache License 2.0 6 votes vote down vote up
ParallelSnapshotScanner(Collection<RowColumn> cells, Environment env, long startTs, TxStats stats,
    Map<Bytes, Set<Column>> readLocksSeen, Consumer<Entry<Key, Value>> writeLocksSeen) {
  for (RowColumn rc : cells) {
    byte[] r = rc.getRow().toArray();
    byte[] cf = rc.getColumn().getFamily().toArray();
    byte[] cq = rc.getColumn().getQualifier().toArray();
    byte[] cv = rc.getColumn().getVisibility().toArray();

    Key start = new Key(r, cf, cq, cv, Long.MAX_VALUE, false, false);
    Key end = new Key(start);
    end.setTimestamp(Long.MIN_VALUE);

    rangesToScan.add(new Range(start, true, end, true));
  }
  this.rows = null;
  this.env = env;
  this.startTs = startTs;
  this.stats = stats;
  this.rowConverter = ByteUtil::toBytes;
  this.columnConverter = ColumnUtil::convert;
  this.readLocksSeen = readLocksSeen;
  this.writeLocksSeen = writeLocksSeen;
}
 
Example 5
Source File: StatsHyperLogReducer.java    From datawave with Apache License 2.0 5 votes vote down vote up
@Override
public void doReduce(BulkIngestKey key, Iterable<Value> values, TaskInputOutputContext<?,?,BulkIngestKey,Value> context) throws IOException,
                InterruptedException {
    log.info("reduce key(" + key.getKey() + ")");
    this.totalKeys++;
    HyperLogLogPlus hllp = new HyperLogLogPlus(this.normalPrecision, this.sparsePrecision);
    HyperLogFieldSummary stats = new HyperLogFieldSummary(hllp);
    int valueCount = 0;
    for (Value val : values) {
        stats.add(val);
        valueCount++;
        if (0 == (valueCount % this.valueInterval) || this.countsOnly) {
            if (this.countsOnly) {
                StatsHyperLogSummary addStats = new StatsHyperLogSummary(val);
                log.info("add values(" + addStats.statsString() + ")");
            }
            log.info("value count(" + valueCount + ")");
        }
    }
    
    log.info("final stats data(" + stats.toString() + ")");
    if (!this.countsOnly) {
        if (this.minCount <= stats.getCount()) {
            // write to bulk output
            StatsCounters counters = stats.toStatsCounters();
            // set timestamp
            Key k = key.getKey();
            k.setTimestamp(this.timestamp);
            writeBulkIngestKey(key, counters.getValue(), context);
        } else {
            log.debug("count is less than minimum: " + key.getKey().toString() + ") count(" + stats.getCount() + ")");
        }
    }
    
    context.progress();
}
 
Example 6
Source File: LockResolver.java    From fluo with Apache License 2.0 5 votes vote down vote up
static List<Entry<Key, Value>> getOpenReadLocks(Environment env,
    Map<Bytes, Set<Column>> rowColsToCheck) throws Exception {

  List<Range> ranges = new ArrayList<>();

  for (Entry<Bytes, Set<Column>> e1 : rowColsToCheck.entrySet()) {
    for (Column col : e1.getValue()) {
      Key start = SpanUtil.toKey(new RowColumn(e1.getKey(), col));
      Key end = new Key(start);
      end.setTimestamp(ColumnType.LOCK.first());
      ranges.add(new Range(start, true, end, false));
    }
  }


  try (BatchScanner bscanner =
      env.getAccumuloClient().createBatchScanner(env.getTable(), env.getAuthorizations(), 1)) {

    bscanner.setRanges(ranges);
    IteratorSetting iterCfg = new IteratorSetting(10, OpenReadLockIterator.class);

    bscanner.addScanIterator(iterCfg);

    List<Entry<Key, Value>> ret = new ArrayList<>();
    for (Entry<Key, Value> entry : bscanner) {
      if (ColumnType.from(entry.getKey()) == ColumnType.RLOCK) {
        ret.add(entry);
      }
    }

    return ret;

  }
}
 
Example 7
Source File: GlobalIndexExpirationFilterTest.java    From accumulo-recipes with Apache License 2.0 5 votes vote down vote up
@Test
public void testExpiration() {

    GlobalIndexExpirationFilter expirationFilter = new GlobalIndexExpirationFilter();

    Key key = new Key();
    key.setTimestamp(System.currentTimeMillis() - 1000);
    assertTrue(expirationFilter.accept(key, new GlobalIndexValue(1, 100000).toValue()));
    assertFalse(expirationFilter.accept(key, new GlobalIndexValue(1, 1).toValue()));
    assertTrue(expirationFilter.accept(key, new GlobalIndexValue(1, -1).toValue()));

    assertTrue(expirationFilter.accept(key, new Value("1".getBytes())));        // test backwards compatibility
}
 
Example 8
Source File: ColumnBuffer.java    From fluo with Apache License 2.0 4 votes vote down vote up
/**
 * @param pos Position of the Key that will be retrieved
 * @return The key at a given position
 */
public Key getKey(int pos) {
  Key tmpKey = new Key(key);
  tmpKey.setTimestamp(timeStamps.get(pos));
  return tmpKey;
}
 
Example 9
Source File: TransactionImpl.java    From fluo with Apache License 2.0 4 votes vote down vote up
private boolean checkForAckCollision(ConditionalMutation cm) {
  Bytes row = Bytes.of(cm.getRow());

  if (isTriggerRow(row)) {
    List<ColumnUpdate> updates = cm.getUpdates();

    for (ColumnUpdate cu : updates) {
      // TODO avoid create col vis object
      Column col = new Column(Bytes.of(cu.getColumnFamily()), Bytes.of(cu.getColumnQualifier()),
          Bytes.of(cu.getColumnVisibility()));

      if (notification.getColumn().equals(col)) {
        // check to see if ACK exist after notification
        Key startKey = SpanUtil.toKey(notification.getRowColumn());
        startKey.setTimestamp(ColumnType.ACK.first());

        Key endKey = SpanUtil.toKey(notification.getRowColumn());
        endKey.setTimestamp(ColumnType.ACK.encode(notification.getTimestamp() + 1));

        Range range = new Range(startKey, endKey);

        try (Scanner scanner =
            env.getAccumuloClient().createScanner(env.getTable(), env.getAuthorizations())) {
          scanner.setRange(range);

          // TODO could use iterator that stops after 1st ACK. thought of using versioning iter
          // but
          // it scans to ACK
          if (scanner.iterator().hasNext()) {
            env.getSharedResources().getBatchWriter()
                .writeMutationAsync(notification.newDelete(env));
            return true;
          }
        } catch (TableNotFoundException e) {
          // TODO proper exception handling
          throw new RuntimeException(e);
        }
      }
    }
  }

  return false;
}
 
Example 10
Source File: ParallelSnapshotScanner.java    From fluo with Apache License 2.0 4 votes vote down vote up
Map<Bytes, Map<Column, Bytes>> scan() {

    long waitTime = SnapshotScanner.INITIAL_WAIT_TIME;
    long startTime = System.currentTimeMillis();

    Map<Bytes, Map<Column, Bytes>> ret = new HashMap<>();

    while (true) {
      List<Entry<Key, Value>> locks = new ArrayList<>();

      scan(ret, locks);

      if (!locks.isEmpty()) {

        boolean resolvedAll = LockResolver.resolveLocks(env, startTs, stats, locks, startTime);

        if (!resolvedAll) {
          UtilWaitThread.sleep(waitTime);
          stats.incrementLockWaitTime(waitTime);
          waitTime = Math.min(SnapshotScanner.MAX_WAIT_TIME, waitTime * 2);
        }

        // retain the rows that were locked for future scans
        rangesToScan.clear();
        rows = null;
        for (Entry<Key, Value> entry : locks) {
          Key start = new Key(entry.getKey());
          start.setTimestamp(Long.MAX_VALUE);
          Key end = new Key(entry.getKey());
          end.setTimestamp(Long.MIN_VALUE);
          rangesToScan.add(new Range(start, true, end, true));
        }

        continue;
      }

      for (Map<Column, Bytes> cols : ret.values()) {
        stats.incrementEntriesReturned(cols.size());
      }

      return ret;
    }
  }