private boolean isDeleted(ByteBuffer value) { //first byte determines the value type byte valType = value.get(value.position()); return SoplogToken.isTombstone(valType) || SoplogToken.isRemovedPhase2(valType); }
public void testSearch() throws IOException { byte[] k1 = comp.createCompositeKey(convert("aaaa"), convert(1), convert(true)); byte[] k2 = comp.createCompositeKey(convert("bbbb"), convert(2), convert(false)); byte[] k3 = comp.createCompositeKey(convert("bbbb"), convert(3), convert(true)); byte[] k4 = comp.createCompositeKey(convert("cccc"), convert(1), convert(false)); byte[] s1 = comp.createCompositeKey(convert("aaaa"), new byte[] {SoplogToken.WILDCARD.toByte()}, new byte[] {SoplogToken.WILDCARD.toByte()}); byte[] s2 = comp.createCompositeKey(convert("bbbb"), new byte[] {SoplogToken.WILDCARD.toByte()}, new byte[] {SoplogToken.WILDCARD.toByte()}); byte[] s3 = comp.createCompositeKey(new byte[] {SoplogToken.WILDCARD.toByte()}, convert(1), new byte[] {SoplogToken.WILDCARD.toByte()}); compareAsIs(comp, k1, s1, Comparison.EQ); compareAsIs(comp, k2, s1, Comparison.GT); compareAsIs(comp, k1, s2, Comparison.LT); compareAsIs(comp, k2, s2, Comparison.EQ); compareAsIs(comp, k3, s2, Comparison.EQ); compareAsIs(comp, k4, s2, Comparison.GT); compareAsIs(comp, s3, k4, Comparison.EQ); }
@Override public int compare(byte[] b1, int o1, int l1, byte[] b2, int o2, int l2) { int klen1 = Bytes.getVarInt(b1, o1); int klen2 = Bytes.getVarInt(b2, o2); int off1 = o1 + Bytes.sizeofVarInt(klen1); int off2 = o2 + Bytes.sizeofVarInt(klen2); // skip the comparison operation if there is a SearchToken.WILDCARD if (!SoplogToken.isWildcard(b1, off1, b2, off2)) { int diff = primary.compare(b1, off1, klen1, b2, off2, klen2); if (diff != 0) { return diff; } } off1 += klen1; off2 += klen2; if (!SoplogToken.isWildcard(b1, off1, b2, off2)) { l1 -= (off1 - o1); l2 -= (off2 - o2); return secondary.compare(b1, off1, l1, b2, off2, l2); } return 0; }
public void testSearch() throws IOException { byte[] k1 = comp.createCompositeKey(convert("aaaa"), convert(1)); byte[] k2 = comp.createCompositeKey(convert("bbbb"), convert(2)); byte[] k3 = comp.createCompositeKey(convert("bbbb"), convert(3)); byte[] k4 = comp.createCompositeKey(convert(null), convert(1)); byte[] s1 = comp.createCompositeKey(convert("aaaa"), new byte[] {SoplogToken.WILDCARD.toByte()}); byte[] s2 = comp.createCompositeKey(convert("bbbb"), new byte[] {SoplogToken.WILDCARD.toByte()}); byte[] s3 = comp.createCompositeKey(new byte[] {SoplogToken.WILDCARD.toByte()}, convert(1)); compareAsIs(comp, k1, s1, Comparison.EQ); compareAsIs(comp, k2, s1, Comparison.GT); compareAsIs(comp, k1, s2, Comparison.LT); compareAsIs(comp, k2, s2, Comparison.EQ); compareAsIs(comp, k3, s2, Comparison.EQ); compareAsIs(comp, k4, s2, Comparison.GT); compareAsIs(comp, s3, k4, Comparison.EQ); }
@Override public int compare(byte[] b1, int o1, int l1, byte[] b2, int o2, int l2) { SerializedComparator[] sc = comparators; int off1 = o1; int off2 = o2; for (int i = 0; i < sc.length - 1; i++) { int klen1 = Bytes.getVarInt(b1, off1); int klen2 = Bytes.getVarInt(b2, off2); off1 += Bytes.sizeofVarInt(klen1); off2 += Bytes.sizeofVarInt(klen2); if (!SoplogToken.isWildcard(b1, off1, b2, off2)) { int diff = sc[i].compare(b1, off1, klen1, b2, off2, klen2); if (diff != 0) { return diff; } } off1 += klen1; off2 += klen2; } if (!SoplogToken.isWildcard(b1, off1, b2, off2)) { l1 -= (off1 - o1); l2 -= (off2 - o2); return sc[sc.length - 1].compare(b1, off1, l1, b2, off2, l2); } return 0; }
public void testTombstone() throws Exception { FlushCounter handler = new FlushCounter(); SortedOplogFactory factory = new HFileSortedOplogFactory("tombstone", null, new SortedOplogStatistics("stats", "tombstone"), new HFileStoreStatistics("storeStats", "tombstone")); Compactor compactor = new SizeTieredCompactor(factory, NonCompactor.createFileset("tombstone", new File(".")), new FileTracker(), Executors.newSingleThreadExecutor(), 2, 2); SortedOplogSet sos = new SortedOplogSetImpl(factory, Executors.newSingleThreadExecutor(), compactor); for (int i = 0; i < 1000; i++) { sos.put(wrapInt(i), wrapInt(i)); } sos.flush(null, handler); for (int i = 900; i < 1000; i++) { sos.put(wrapInt(i), new byte[] {SoplogToken.TOMBSTONE.toByte()}); } flushAndWait(handler, sos); compactAndWait(sos, true); validate(sos, 900); sos.close(); }