public static boolean isMetaEditFamily(Cell cell) { return CellUtil.matchingFamily(cell, METAFAMILY); }
/** * Return HStore instance. Does not do any copy: as the number of store is limited, we iterate on * the list. */ private HStore getStore(Cell cell) { return stores.entrySet().stream().filter(e -> CellUtil.matchingFamily(cell, e.getKey())) .map(e -> e.getValue()).findFirst().orElse(null); }
public static boolean matchingColumn(final Cell left, final byte[] fam, final byte[] qual) { if (!matchingFamily(left, fam)) return false; return matchingQualifier(left, qual); }
public static boolean matchingColumn(final Cell left, final Cell right) { if (!matchingFamily(left, right)) return false; return matchingQualifier(left, right); }
public static boolean matchingFamily(final Cell left, final byte[] buf) { if (buf == null) { return left.getFamilyLength() == 0; } return matchingFamily(left, buf, 0, buf.length); }
@VisibleForTesting static Set<byte[]> collectFamilies(List<Cell> cells) { if (CollectionUtils.isEmpty(cells)) { return Collections.emptySet(); } else { return cells.stream() .filter(v -> !CellUtil.matchingFamily(v, WALEdit.METAFAMILY)) .collect(toCollection(() -> new TreeSet<>(CellComparator.getInstance()::compareFamilies))) .stream() .map(CellUtil::cloneFamily) .collect(toCollection(() -> new TreeSet<>(Bytes.BYTES_COMPARATOR))); } }
private boolean hasColumn(final List<Cell> kvs, final byte [] family, final byte [] qualifier) { for (Cell kv: kvs) { if (CellUtil.matchingFamily(kv, family) && CellUtil.matchingQualifier(kv, qualifier)) { return true; } } return false; }
private Cell getColumn(final List<Cell> kvs, final byte [] family, final byte [] qualifier) { for (Cell kv: kvs) { if (CellUtil.matchingFamily(kv, family) && CellUtil.matchingQualifier(kv, qualifier)) { return kv; } } return null; }
private boolean filter(Entry entry) { WALEdit edit = entry.getEdit(); WALUtil.filterCells(edit, c -> CellUtil.matchingFamily(c, WALEdit.METAFAMILY) ? null : c); return !edit.isEmpty(); }
/** * Utility method used to set the correct scopes on each log key. Doesn't set a scope on keys from * compaction WAL edits and if the scope is local. * @param logKey Key that may get scoped according to its edits * @param logEdit Edits used to lookup the scopes */ @VisibleForTesting static void scopeWALEdits(WALKey logKey, WALEdit logEdit, Configuration conf) { // For bulk load replication we need meta family to know the file we want to replicate. if (ReplicationUtils.isReplicationForBulkLoadDataEnabled(conf)) { return; } // For replay, or if all the cells are markers, do not need to store replication scope. if (logEdit.isReplay() || logEdit.getCells().stream().allMatch(c -> CellUtil.matchingFamily(c, WALEdit.METAFAMILY))) { ((WALKeyImpl) logKey).clearReplicationScope(); } } }
/**************** equals ****************************/ public static boolean equals(Cell a, Cell b) { return matchingRows(a, b) && matchingFamily(a, b) && matchingQualifier(a, b) && matchingTimestamp(a, b) && PrivateCellUtil.matchingType(a, b); }
/** * Checks if this permission grants access to perform the given action on * the given table and key value. * @param table the table on which the operation is being performed * @param kv the KeyValue on which the operation is being requested * @param action the action requested * @return <code>true</code> if the action is allowed over the given scope * by this permission, otherwise <code>false</code> */ public boolean implies(TableName table, KeyValue kv, Action action) { if (failCheckTable(table)) { return false; } if (family != null && !(CellUtil.matchingFamily(kv, family))) { return false; } if (qualifier != null && !(CellUtil.matchingQualifier(kv, qualifier))) { return false; } // check actions return super.implies(action); }
void filterCellByStore(Entry logEntry) { Map<byte[], Long> maxSeqIdInStores = regionMaxSeqIdInStores.get(Bytes.toString(logEntry.getKey().getEncodedRegionName())); if (MapUtils.isEmpty(maxSeqIdInStores)) { return; } // Create the array list for the cells that aren't filtered. // We make the assumption that most cells will be kept. ArrayList<Cell> keptCells = new ArrayList<>(logEntry.getEdit().getCells().size()); for (Cell cell : logEntry.getEdit().getCells()) { if (CellUtil.matchingFamily(cell, WALEdit.METAFAMILY)) { keptCells.add(cell); } else { byte[] family = CellUtil.cloneFamily(cell); Long maxSeqId = maxSeqIdInStores.get(family); // Do not skip cell even if maxSeqId is null. Maybe we are in a rolling upgrade, // or the master was crashed before and we can not get the information. if (maxSeqId == null || maxSeqId.longValue() < logEntry.getKey().getSequenceId()) { keptCells.add(cell); } } } // Anything in the keptCells array list is still live. // So rather than removing the cells from the array list // which would be an O(n^2) operation, we just replace the list logEntry.getEdit().setCells(keptCells); }
private void verifyScanFull(Scan s, KeyValue [] kvs) throws IOException { InternalScanner scanner = this.region.getScanner(s); List<Cell> results = new ArrayList<>(); int row = 0; int idx = 0; for (boolean done = true; done; row++) { done = scanner.next(results); Arrays.sort(results.toArray(new Cell[results.size()]), CellComparator.getInstance()); if(results.isEmpty()) break; assertTrue("Scanned too many keys! Only expected " + kvs.length + " total but already scanned " + (results.size() + idx) + (results.isEmpty() ? "" : "(" + results.get(0).toString() + ")"), kvs.length >= idx + results.size()); for (Cell kv : results) { LOG.info("row=" + row + ", result=" + kv.toString() + ", match=" + kvs[idx].toString()); assertTrue("Row mismatch", CellUtil.matchingRows(kv, kvs[idx])); assertTrue("Family mismatch", CellUtil.matchingFamily(kv, kvs[idx])); assertTrue("Qualifier mismatch", CellUtil.matchingQualifier(kv, kvs[idx])); assertTrue("Value mismatch", CellUtil.matchingValue(kv, kvs[idx])); idx++; } results.clear(); } LOG.info("Looked at " + row + " rows with " + idx + " keys"); assertEquals("Expected " + kvs.length + " total keys but scanned " + idx, kvs.length, idx); }
private void verifyData( final HRegion newReg, final int startRow, final int numRows, final byte[]... families) throws IOException { for (int i = startRow; i < startRow + numRows; i++) { byte[] row = Bytes.toBytes("" + i); Get get = new Get(row); Result result = newReg.get(get); Cell[] raw = result.rawCells(); assertEquals(families.length, result.size()); for (int j = 0; j < families.length; j++) { assertTrue(CellUtil.matchingRows(raw[j], row)); assertTrue(CellUtil.matchingFamily(raw[j], families[j])); } } }
private void assertNResult(Result result, byte [] row, byte [] family, byte [] qualifier, long [] stamps, byte [][] values, int start, int end) throws IOException { assertTrue("Expected row [" + Bytes.toString(row) + "] " + "Got row [" + Bytes.toString(result.getRow()) +"]", equals(row, result.getRow())); int expectedResults = end - start + 1; assertEquals(expectedResults, result.size()); Cell[] keys = result.rawCells(); for (int i=0; i<keys.length; i++) { byte [] value = values[end-i]; long ts = stamps[end-i]; Cell key = keys[i]; assertTrue("(" + i + ") Expected family [" + Bytes.toString(family) + "] " + "Got family [" + Bytes.toString(CellUtil.cloneFamily(key)) + "]", CellUtil.matchingFamily(key, family)); assertTrue("(" + i + ") Expected qualifier [" + Bytes.toString(qualifier) + "] " + "Got qualifier [" + Bytes.toString(CellUtil.cloneQualifier(key))+ "]", CellUtil.matchingQualifier(key, qualifier)); assertTrue("Expected ts [" + ts + "] " + "Got ts [" + key.getTimestamp() + "]", ts == key.getTimestamp()); assertTrue("(" + i + ") Expected value [" + Bytes.toString(value) + "] " + "Got value [" + Bytes.toString(CellUtil.cloneValue(key)) + "]", CellUtil.matchingValue(key, value)); } }
@Override public void postGetOp(final ObserverContext<RegionCoprocessorEnvironment> c, final Get get, final List<Cell> results) { RegionCoprocessorEnvironment e = c.getEnvironment(); assertNotNull(e); assertNotNull(e.getRegion()); assertNotNull(get); assertNotNull(results); if (e.getRegion().getTableDescriptor().getTableName().equals( TestRegionObserverInterface.TEST_TABLE)) { boolean foundA = false; boolean foundB = false; boolean foundC = false; for (Cell kv: results) { if (CellUtil.matchingFamily(kv, TestRegionObserverInterface.A)) { foundA = true; } if (CellUtil.matchingFamily(kv, TestRegionObserverInterface.B)) { foundB = true; } if (CellUtil.matchingFamily(kv, TestRegionObserverInterface.C)) { foundC = true; } } assertTrue(foundA); assertTrue(foundB); assertTrue(foundC); } ctPostGet.incrementAndGet(); }
if (!qualSet.isEmpty() && (!CellUtil.matchingFamily(kv, FAMILY_BYTES) || !qualSet.contains(Bytes.toString(CellUtil.cloneQualifier(kv))))) { continue;
private void verifyData(Region newReg, int startRow, int numRows, byte[] qf, byte[]... families) throws IOException { for (int i = startRow; i < startRow + numRows; i++) { byte[] row = Bytes.toBytes("" + i); Get get = new Get(row); for (byte[] family : families) { get.addColumn(family, qf); } Result result = newReg.get(get); Cell[] raw = result.rawCells(); assertEquals(families.length, result.size()); for (int j = 0; j < families.length; j++) { assertTrue(CellUtil.matchingRows(raw[j], row)); assertTrue(CellUtil.matchingFamily(raw[j], families[j])); assertTrue(CellUtil.matchingQualifier(raw[j], qf)); } } }
static void verifyData(HRegion newReg, int startRow, int numRows, byte[] qf, byte[]... families) throws IOException { for (int i = startRow; i < startRow + numRows; i++) { byte[] row = Bytes.toBytes("" + i); Get get = new Get(row); for (byte[] family : families) { get.addColumn(family, qf); } Result result = newReg.get(get); Cell[] raw = result.rawCells(); assertEquals(families.length, result.size()); for (int j = 0; j < families.length; j++) { assertTrue(CellUtil.matchingRows(raw[j], row)); assertTrue(CellUtil.matchingFamily(raw[j], families[j])); assertTrue(CellUtil.matchingQualifier(raw[j], qf)); } } }