public FluoMutationGenerator put(Column col, Text value) { return put(col, ByteUtil.toBytes(value)); }
void scan(Map<Bytes, Map<Column, Bytes>> ret, List<Entry<Key, Value>> locks) { BatchScanner bs = setupBatchScanner(unscannedRows, columns); try { for (Entry<Key, Value> entry : bs) { Bytes row = ByteUtil.toBytes(entry.getKey().getRowData()); Bytes cf = ByteUtil.toBytes(entry.getKey().getColumnFamilyData()); Bytes cq = ByteUtil.toBytes(entry.getKey().getColumnQualifierData()); Column col = new Column(cf, cq, ByteUtil.toBytes(entry.getKey().getColumnVisibilityData())); long colType = entry.getKey().getTimestamp() & ColumnConstants.PREFIX_MASK; if (colType == ColumnConstants.LOCK_PREFIX) { locks.add(entry); } else if (colType == ColumnConstants.DATA_PREFIX) { Map<Column, Bytes> cols = ret.get(row); if (cols == null) { cols = new HashMap<>(); ret.put(row, cols); } cols.put(col, Bytes.of(entry.getValue().get())); } else { throw new IllegalArgumentException("Unexpected column type " + colType); } } } finally { bs.close(); } }
@Override public Entry<Column, Bytes> next() { Entry<Key, Value> entry; if (firstEntry != null) { entry = firstEntry; firstEntry = null; } else { entry = scanner.next(); } final Bytes cf = ByteUtil.toBytes(entry.getKey().getColumnFamilyData()); final Bytes cq = ByteUtil.toBytes(entry.getKey().getColumnQualifierData()); final Bytes cv = ByteUtil.toBytes(entry.getKey().getColumnVisibilityData()); final Column col = new Column(cf, cq, cv); final Bytes val = Bytes.of(entry.getValue().get()); return new Entry<Column, Bytes>() { @Override public Bytes setValue(Bytes value) { throw new UnsupportedOperationException(); } @Override public Bytes getValue() { return val; } @Override public Column getKey() { return col; } }; }
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.size() > 0) { 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); } // TODO, could only rescan the row/cols that were locked instead of just the entire row // retain the rows that were locked for future scans HashSet<Bytes> lockedRows = new HashSet<>(); for (Entry<Key, Value> entry : locks) { lockedRows.add(ByteUtil.toBytes(entry.getKey().getRowData())); } unscannedRows.retainAll(lockedRows); continue; } for (Map<Column, Bytes> cols : ret.values()) { stats.incrementEntriesReturned(cols.size()); } return ret; } }
public static Notification from(Key k) { Preconditions.checkArgument(!isDelete(k), "Method not expected to be used with delete notifications"); Bytes row = ByteUtil.toBytes(k.getRowData()); return new Notification(row, decodeCol(k), decodeTs(k)); }
private static boolean isPrimary(PrimaryRowColumn prc, Key k) { return prc.prow.equals(ByteUtil.toBytes(k.getRowData())) && prc.pcol.equals(SpanUtil.toRowColumn(k).getColumn()); } }
/** * Converts from an Accumulo Key to a Fluo RowColumn * * @param key Key * @return RowColumn */ public static RowColumn toRowColumn(Key key) { if (key == null) { return RowColumn.EMPTY; } if ((key.getRow() == null) || key.getRow().getLength() == 0) { return RowColumn.EMPTY; } Bytes row = ByteUtil.toBytes(key.getRow()); if ((key.getColumnFamily() == null) || key.getColumnFamily().getLength() == 0) { return new RowColumn(row); } Bytes cf = ByteUtil.toBytes(key.getColumnFamily()); if ((key.getColumnQualifier() == null) || key.getColumnQualifier().getLength() == 0) { return new RowColumn(row, new Column(cf)); } Bytes cq = ByteUtil.toBytes(key.getColumnQualifier()); if ((key.getColumnVisibility() == null) || key.getColumnVisibility().getLength() == 0) { return new RowColumn(row, new Column(cf, cq)); } Bytes cv = ByteUtil.toBytes(key.getColumnVisibility()); return new RowColumn(row, new Column(cf, cq, cv)); } }