/** * Converts an Accumulo Range to a Fluo Span * * @param range Range * @return Span */ public static Span toSpan(Range range) { return new Span(toRowColumn(range.getStartKey()), range.isStartKeyInclusive(), toRowColumn(range.getEndKey()), range.isEndKeyInclusive()); }
@Override public void initialize(InputSplit split, TaskAttemptContext context) throws IOException, InterruptedException { try { ByteArrayInputStream bais = new ByteArrayInputStream(context.getConfiguration().get(PROPS_CONF_KEY) .getBytes("UTF-8")); PropertiesConfiguration props = new PropertiesConfiguration(); props.load(bais); env = new Environment(new FluoConfiguration(props)); ti = new TransactionImpl(env, context.getConfiguration().getLong(TIMESTAMP_CONF_KEY, -1)); // TODO this uses non public Accumulo API! RangeInputSplit ris = (RangeInputSplit) split; Span span = SpanUtil.toSpan(ris.getRange()); ScannerConfiguration sc = new ScannerConfiguration().setSpan(span); for (String fam : context.getConfiguration().getStrings(FAMS_CONF_KEY, new String[0])) { sc.fetchColumnFamily(Bytes.of(fam)); } rowIter = ti.get(sc); } catch (Exception e) { throw new IOException(e); } }
scanner.setRange(SpanUtil.toRange(scanConfig.getSpan())); for (Column col : scanConfig.getColumns()) { if (col.isQualifierSet()) {
private void setUpIterator() { Scanner scanner; try { scanner = env.getConnector().createScanner(env.getTable(), env.getAuthorizations()); } catch (TableNotFoundException e) { throw new RuntimeException(e); } scanner.clearColumns(); scanner.clearScanIterators(); scanner.setRange(SpanUtil.toRange(config.getSpan())); setupScanner(scanner, config.getColumns(), startTs); this.iterator = scanner.iterator(); }
public static Entry<Key, Value> checkColumn(Environment env, IteratorSetting iterConf, Bytes row, Column col) { Span span = Span.exact(row, col); Scanner scanner; try { // TODO reuse or share scanner scanner = env.getConnector().createScanner(env.getTable(), env.getAuthorizations()); } catch (TableNotFoundException e) { // TODO proper exception handling throw new RuntimeException(e); } scanner.setRange(SpanUtil.toRange(span)); scanner.addScanIterator(iterConf); Iterator<Entry<Key, Value>> iter = scanner.iterator(); if (iter.hasNext()) { Entry<Key, Value> entry = iter.next(); Key k = entry.getKey(); Bytes r = Bytes.of(k.getRowData().toArray()); Bytes cf = Bytes.of(k.getColumnFamilyData().toArray()); Bytes cq = Bytes.of(k.getColumnQualifierData().toArray()); Bytes cv = Bytes.of(k.getColumnVisibilityData().toArray()); if (r.equals(row) && cf.equals(col.getFamily()) && cq.equals(col.getQualifier()) && cv.equals(col.getVisibility())) { return entry; } else { throw new RuntimeException("unexpected key " + k + " " + row + " " + col); } } return null; }
waitTime = Math.min(MAX_WAIT_TIME, waitTime * 2); RowColumn start = SpanUtil.toRowColumn(locks.get(0).getKey()); RowColumn end = SpanUtil.toRowColumn(locks.get(locks.size() - 1).getKey()).following(); RowColumn start = SpanUtil.toRowColumn(lockEntry.getKey());
@Override public void initialize(InputSplit split, TaskAttemptContext context) throws IOException, InterruptedException { try { ByteArrayInputStream bais = new ByteArrayInputStream(context.getConfiguration().get(PROPS_CONF_KEY) .getBytes("UTF-8")); PropertiesConfiguration props = new PropertiesConfiguration(); props.load(bais); env = new Environment(new FluoConfiguration(props)); ti = new TransactionImpl(env, context.getConfiguration().getLong(TIMESTAMP_CONF_KEY, -1)); // TODO this uses non public Accumulo API! RangeInputSplit ris = (RangeInputSplit) split; Span span = SpanUtil.toSpan(ris.getRange()); ScannerConfiguration sc = new ScannerConfiguration().setSpan(span); for (String fam : context.getConfiguration().getStrings(FAMS_CONF_KEY, new String[0])) { sc.fetchColumnFamily(Bytes.of(fam)); } rowIter = ti.get(sc); } catch (Exception e) { throw new IOException(e); } }
private static void commitColumns(Environment env, PrimaryRowColumn prc, List<Entry<Key, Value>> value, long commitTs, Map<ByteSequence, Mutation> mutations) { for (Entry<Key, Value> entry : value) { if (isPrimary(prc, entry.getKey())) { continue; } long lockTs = entry.getKey().getTimestamp() & ColumnConstants.TIMESTAMP_MASK; // TODO may be that a stronger sanity check that could be done here if (commitTs < lockTs) { throw new IllegalStateException("bad commitTs : " + entry.getKey() + " (" + commitTs + "<" + lockTs + ")"); } Mutation mut = getMutation(entry.getKey().getRowData(), mutations); Column col = SpanUtil.toRowColumn(entry.getKey()).getColumn(); LockValue lv = new LockValue(entry.getValue().get()); ColumnUtil.commitColumn(env, lv.isTrigger(), false, col, lv.isWrite(), lv.isDelete(), lockTs, commitTs, env.getObservers().keySet(), mut); } }
private static boolean isPrimary(PrimaryRowColumn prc, Key k) { return prc.prow.equals(ByteUtil.toBytes(k.getRowData())) && prc.pcol.equals(SpanUtil.toRowColumn(k).getColumn()); } }