@Override public void deserialize(Entry<Key, Value> entry) { if (!columnValues.containsKey(rowIdName)) { entry.getKey().getRow(rowId); columnValues.put(rowIdName, rowId.toString()); } if (rowOnly) { return; } entry.getKey().getColumnFamily(family); entry.getKey().getColumnQualifier(qualifier); if (family.equals(ROW_ID_COLUMN) && qualifier.equals(ROW_ID_COLUMN)) { return; } value.set(entry.getValue().get()); columnValues.put(familyQualifierColumnMap.get(family.toString()).get(qualifier.toString()), value.toString()); }
/** * Deletes a row, given a Scanner of JUST that row. */ private void deleteRow(Scanner scanner, BatchWriter bw) throws MutationsRejectedException { Mutation deleter = null; // iterate through the keys final Text row = new Text(); final Text cf = new Text(); final Text cq = new Text(); for (Entry<Key, Value> entry : scanner) { // create a mutation for the row if (deleter == null) { entry.getKey().getRow(row); deleter = new Mutation(row); } entry.getKey().getColumnFamily(cf); entry.getKey().getColumnQualifier(cq); // the remove function adds the key with the delete flag set to true deleter.putDelete(cf, cq); } bw.addMutation(deleter); } }
private void prepKeys() throws IOException { if (topKey != null) return; Text currentRow; Text currentCf; do { if (!sourceIter.hasTop()) return; currentRow = new Text(sourceIter.getTopKey().getRow()); currentCf = new Text(sourceIter.getTopKey().getColumnFamily()); keys.clear(); values.clear(); while (sourceIter.hasTop() && sourceIter.getTopKey().getRow().equals(currentRow) && sourceIter.getTopKey().getColumnFamily().equals(currentCf)) { keys.add(new Key(sourceIter.getTopKey())); values.add(new Value(sourceIter.getTopValue())); sourceIter.next(); } } while (!filter(currentRow, keys, values)); topKey = new Key(currentRow, currentCf); topValue = encodeColumnFamily(keys, values); }
serializedRow.getKey().getRow(), wholeRow.size()); Text buffer = new Text(); Status status; try { status = Status.parseFrom(entry.getValue().get()); } catch (InvalidProtocolBufferException e) { log.warn("Could not deserialize protobuf for {}", entry.getKey(), e); entry.getKey().getColumnQualifier(buffer); ReplicationTarget target = ReplicationTarget.from(buffer); if (entry.getValue() == 0) { continue; serializedRow.getKey().getRow(buffer); serializedRow.getKey().getRow(), entry.getKey(), entry.getValue()); serializedRow.getKey().getRow(), ProtobufUtil.toString(updatedStatus));
public static SortedMap<Text,SortedMap<ColumnFQ,Value>> getTabletEntries( SortedMap<Key,Value> tabletKeyValues, List<ColumnFQ> columns) { TreeMap<Text,SortedMap<ColumnFQ,Value>> tabletEntries = new TreeMap<>(); HashSet<ColumnFQ> colSet = null; if (columns != null) { colSet = new HashSet<>(columns); } for (Entry<Key,Value> entry : tabletKeyValues.entrySet()) { ColumnFQ currentKey = new ColumnFQ(entry.getKey()); if (columns != null && !colSet.contains(currentKey)) { continue; } Text row = entry.getKey().getRow(); SortedMap<ColumnFQ,Value> colVals = tabletEntries.get(row); if (colVals == null) { colVals = new TreeMap<>(); tabletEntries.put(row, colVals); } colVals.put(currentKey, entry.getValue()); } return tabletEntries; }
Key key = kv.getKey(); String val = kv.getValue().toString(); String fam = key.getColumnFamilyData().toString(); String qual = key.getColumnQualifierData().toString(); kvBuilder.put(key, kv.getValue()); KeyExtent ke = new KeyExtent(key.getRow(), (Text) null); te.endRow = ke.getEndRow(); te.tableId = ke.getTableId(); case TabletColumnFamily.STR_NAME: if (PREV_ROW_QUAL.equals(qual)) { te.prevEndRow = KeyExtent.decodePrevEndRow(kv.getValue()); te.sawPrevEndRow = true;
public static List<LogEntry> getLogEntries(ServerContext context, KeyExtent extent) throws IOException, KeeperException, InterruptedException { log.info("Scanning logging entries for {}", extent); ArrayList<LogEntry> result = new ArrayList<>(); if (extent.equals(RootTable.EXTENT)) { log.info("Getting logs for root tablet from zookeeper"); getRootLogEntries(context, result); } else { log.info("Scanning metadata for logs used for tablet {}", extent); Scanner scanner = getTabletLogScanner(context, extent); Text pattern = extent.getMetadataEntry(); for (Entry<Key,Value> entry : scanner) { Text row = entry.getKey().getRow(); if (entry.getKey().getColumnFamily().equals(LogColumnFamily.NAME)) { if (row.equals(pattern)) { result.add(LogEntry.fromKeyValue(entry.getKey(), entry.getValue())); } } } } log.info("Returning logs {} for extent {}", result, extent); return result; }
/** * Converts the given {@code Range} into the correct {@code Range} for this TermSource (per this * expected table structure) and then seeks this TermSource's SKVI. */ public void seek(Range originalRange) throws IOException { // the infinite start key is equivalent to a null startKey on the Range. if (!originalRange.isInfiniteStartKey()) { Key originalStartKey = originalRange.getStartKey(); // Pivot the provided range into the range for this term Key newKey = new Key(originalStartKey.getRow(), term, originalStartKey.getColumnQualifier(), originalStartKey.getTimestamp()); // Construct the new range, preserving the other attributes on the provided range. currentRange = new Range(newKey, originalRange.isStartKeyInclusive(), originalRange.getEndKey(), originalRange.isEndKeyInclusive()); } else { currentRange = originalRange; } LOG.trace("Seeking {} to {}", this, currentRange); iter.seek(currentRange, seekColfams, true); }
/** * Deletes a row, given a Scanner of JUST that row. */ private void deleteRow(Scanner scanner, BatchWriter bw) throws MutationsRejectedException { Mutation deleter = null; // iterate through the keys final Text row = new Text(); final Text cf = new Text(); final Text cq = new Text(); for (Entry<Key, Value> entry : scanner) { // create a mutation for the row if (deleter == null) { entry.getKey().getRow(row); deleter = new Mutation(row); } entry.getKey().getColumnFamily(cf); entry.getKey().getColumnQualifier(cq); // the remove function adds the key with the delete flag set to true deleter.putDelete(cf, cq); } bw.addMutation(deleter); } }
scanner.fetchColumnFamily(new Text("loc")); location = Optional.of(iter.next().getValue().toString()); Text splitCompareKey = new Text(); key.getRow(splitCompareKey); Text scannedCompareKey = new Text(); byte[] keyBytes = entry.getKey().getRow().copyBytes(); location = Optional.of(entry.getValue().toString()); break; int compareTo = splitCompareKey.compareTo(scannedCompareKey); if (compareTo <= 0) { location = Optional.of(entry.getValue().toString());
@Override public void deserialize(Entry<Key, Value> entry) { if (!columnValues.containsKey(rowIdName)) { entry.getKey().getRow(rowId); columnValues.put(rowIdName, rowId.copyBytes()); } if (rowOnly) { return; } entry.getKey().getColumnFamily(family); entry.getKey().getColumnQualifier(qualifier); if (family.equals(ROW_ID_COLUMN) && qualifier.equals(ROW_ID_COLUMN)) { return; } value.set(entry.getValue().get()); columnValues.put(familyQualifierColumnMap.get(family.toString()).get(qualifier.toString()), value.copyBytes()); }
startRow = range.getStartKey().getRow(); else startRow = new Text(); Key key = entry.getKey(); if (key.getColumnFamily() .equals(MetadataSchema.TabletsSection.LastLocationColumnFamily.NAME)) { last = entry.getValue().toString(); if (key.getColumnFamily() .equals(MetadataSchema.TabletsSection.CurrentLocationColumnFamily.NAME) || key.getColumnFamily() .equals(MetadataSchema.TabletsSection.FutureLocationColumnFamily.NAME)) { location = entry.getValue().toString(); extent = new KeyExtent(key.getRow(), entry.getValue());
public static RealMatrix buildMatrix(Iterator<Map.Entry<Key, Value>> iter, int dimension) { RealMatrix matrix = MatrixUtils.createRealMatrix(dimension, dimension); Text row = new Text(), col = new Text(); while (iter.hasNext()) { Map.Entry<Key, Value> entry = iter.next(); Key k = entry.getKey(); int r = Integer.parseInt(k.getRow(row).toString()) - 1, c = Integer.parseInt(k.getColumnQualifier(col).toString()) - 1; double v = Double.parseDouble(new String(entry.getValue().get(), StandardCharsets.UTF_8)); // StandardCharsets.UTF_8? matrix.setEntry(r, c, v); } return matrix; }
/** * SingleRowIter must be passed a PeekingIterator so that it can peek at the next entry to see * if it belongs in the current row or not. */ public SingleRowIter(PeekingIterator<Entry<Key,Value>> source) { this.source = source; if (source.hasNext()) currentRow = source.peek().getKey().getRow(); }
@Override public Key getNextKeyHint(Key k, Value v) throws IllegalArgumentException { if (cso.minCf.getLength() > 0) { int minCfCmp = k.compareColumnFamily(cso.minCf); if (minCfCmp < 0) { Key hint = new Key(k.getRow(), cso.minCf); return cso.minInclusive ? hint : hint.followingKey(PartialKey.ROW_COLFAM); } } if (cso.minCq.getLength() > 0) { int minCqCmp = k.compareColumnQualifier(cso.minCq); if (minCqCmp < 0) { Key hint = new Key(k.getRow(), k.getColumnFamily(), cso.minCq); return cso.minInclusive ? hint : hint.followingKey(PartialKey.ROW_COLFAM_COLQUAL); } } // If we get here it means that we were asked to provide a hint for a key that we // didn't return USE_HINT for. throw new IllegalArgumentException("Don't know how to provide hint for key " + k); }
/** * Deletes a row, given a Scanner of JUST that row. */ private void deleteRow(Scanner scanner, BatchWriter bw) throws MutationsRejectedException { Mutation deleter = null; // iterate through the keys final Text row = new Text(); final Text cf = new Text(); final Text cq = new Text(); for (Entry<Key, Value> entry : scanner) { // create a mutation for the row if (deleter == null) { entry.getKey().getRow(row); deleter = new Mutation(row); } entry.getKey().getColumnFamily(cf); entry.getKey().getColumnQualifier(cq); // the remove function adds the key with the delete flag set to true deleter.putDelete(cf, cq); } bw.addMutation(deleter); } }
private static void assertKeyValuePair(Entry<Key, Value> e, byte[] row, String cf, String cq, String value) { assertEquals(row, e.getKey().getRow().copyBytes()); assertEquals(cf, e.getKey().getColumnFamily().toString()); assertEquals(cq, e.getKey().getColumnQualifier().toString()); assertEquals(value, e.getValue().toString()); }
/** * If a migrating tablet splits, and the tablet dies before sending the master a message, the * migration will refer to a non-existing tablet, so it can never complete. Periodically scan * the metadata table and remove any migrating tablets that no longer exist. */ private void cleanupNonexistentMigrations(final AccumuloClient accumuloClient) throws TableNotFoundException { Scanner scanner = accumuloClient.createScanner(MetadataTable.NAME, Authorizations.EMPTY); TabletsSection.TabletColumnFamily.PREV_ROW_COLUMN.fetch(scanner); Set<KeyExtent> found = new HashSet<>(); for (Entry<Key,Value> entry : scanner) { KeyExtent extent = new KeyExtent(entry.getKey().getRow(), entry.getValue()); if (migrations.containsKey(extent)) { found.add(extent); } } migrations.keySet().retainAll(found); }