public FluoMutationGenerator put(Column col, Text value) { return put(col, ByteUtil.toBytes(value)); }
public Flutation(Environment env, Bytes row) { super(ByteUtil.toText(row)); this.env = env; }
/** * @return this */ public FluoKeyValueGenerator setRow(Text row) { this.row = ByteUtil.toByteArray(row); return this; }
public ConditionalFlutation(Environment env, Bytes row) { super(ByteUtil.toByteSequence(row)); this.env = env; }
public ConditionalFlutation(Environment env, Bytes row, Condition condition) { super(ByteUtil.toByteSequence(row), condition); this.env = env; }
@Override public ColumnVisibility call() throws Exception { return new ColumnVisibility(ByteUtil.toText(colvis)); } });
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(); } }
@VisibleForTesting static boolean shouldProcess(Notification notification, int divisor, int remainder) { byte[] cfcq = NotificationUtil.encodeCol(notification.getColumn()); return NotificationHashFilter.accept( ByteUtil.toByteSequence((MutableBytes) notification.getRow()), new ArrayByteSequence(cfcq), divisor, remainder); }
/** * @return this */ public FluoKeyValueGenerator setValue(Text val) { this.val = ByteUtil.toByteArray(val); return this; }
public static void configureScanner(Scanner scanner) { scanner.fetchColumnFamily(ByteUtil.toText(ColumnConstants.NOTIFY_CF)); scanner.addScanIterator(new IteratorSetting(11, NotificationIterator.class)); } }
@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; } }; }
public FluoCondition(Environment env, Column col) { super(ByteUtil.toByteSequence(col.getFamily()), ByteUtil.toByteSequence(col.getQualifier())); if (col.getVisibility().length() > 0) { setVisibility(env.getSharedResources().getVisCache().getCV(col)); } }
static void setupScanner(ScannerBase scanner, Set<Column> columns, long startTs) { for (Column col : columns) { if (col.isQualifierSet()) { scanner.fetchColumn(ByteUtil.toText(col.getFamily()), ByteUtil.toText(col.getQualifier())); } else { scanner.fetchColumnFamily(ByteUtil.toText(col.getFamily())); } } IteratorSetting iterConf = new IteratorSetting(10, SnapshotIterator.class); SnapshotIterator.setSnaptime(iterConf, startTs); scanner.addScanIterator(iterConf); }
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 void put(Environment env, Mutation m, Column col, long ts, byte[] val) { ColumnVisibility cv; if (env != null) { cv = env.getSharedResources().getVisCache().getCV(col.getVisibility()); } else if (col.getVisibility().length() == 0) { cv = VisibilityCache.EMPTY_VIS; } else { cv = new ColumnVisibility(ByteUtil.toText(col.getVisibility())); } m.put(ByteUtil.toText(col.getFamily()), ByteUtil.toText(col.getQualifier()), cv, ts, new Value( val)); } }
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()); } }
private BatchScanner setupBatchScanner(Collection<Bytes> rows, Set<Column> columns) { BatchScanner scanner; try { // TODO hardcoded number of threads! // one thread is probably good.. going for throughput scanner = env.getConnector().createBatchScanner(env.getTable(), env.getAuthorizations(), 1); } catch (TableNotFoundException e) { throw new RuntimeException(e); } scanner.clearColumns(); scanner.clearScanIterators(); List<Range> ranges = new ArrayList<>(rows.size()); for (Bytes row : rows) { ranges.add(Range.exact(ByteUtil.toText(row))); } scanner.setRanges(ranges); SnapshotScanner.setupScanner(scanner, columns, startTs); return scanner; }
/** * 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)); } }