public void testClearInterruptsFlush() throws Exception { FlushCounter handler = new FlushCounter(); SortedOplogSetImpl sos = prepSoplogSet("clearDuringFlush"); sos.testDelayDuringFlush = new CountDownLatch(1); sos.flush(null, handler); sos.clear(); flushAndWait(handler, sos); validateEmpty(sos); assertEquals(2, handler.flushes.get()); }
public void testCloseInterruptsFlush() throws Exception { FlushCounter handler = new FlushCounter(); SortedOplogSetImpl sos = prepSoplogSet("closeDuringFlush"); sos.testDelayDuringFlush = new CountDownLatch(1); sos.flush(null, handler); sos.close(); assertTrue(sos.isClosed()); assertEquals(1, handler.flushes.get()); }
public void testDestroyInterruptsFlush() throws Exception { FlushCounter handler = new FlushCounter(); SortedOplogSetImpl sos = prepSoplogSet("destroyDuringFlush"); sos.testDelayDuringFlush = new CountDownLatch(1); sos.flush(null, handler); sos.destroy(); assertTrue(sos.isClosed()); assertEquals(1, handler.flushes.get()); }
@Override public void flushAndClose(EnumMap<Metadata, byte[]> metadata) throws IOException { final AtomicReference<Throwable> err = new AtomicReference<Throwable>(null); flush(metadata, new FlushHandler() { @Override public void complete() { } @Override public void error(Throwable t) { err.set(t); } }); // waits for flush completion close(); Throwable t = err.get(); if (t != null) { throw new IOException(t); } }
@Override public void destroy() throws IOException { if (logger.fineEnabled()) { logger.fine("Destroying soplog set"); } long start = factory.getConfiguration().getStatistics().getDestroy().begin(); try { unsetCurrent(); clear(); close(); factory.getConfiguration().getStatistics().getDestroy().end(start); } catch (IOException e) { factory.getConfiguration().getStatistics().getDestroy().error(start); throw (IOException) e.fillInStackTrace(); } }
rwlock.writeLock().lock(); try { if (isClosed()) { handler.complete(); factory.getConfiguration().getStatistics().getFlush().end(0, start); sb = flipBuffer(); if (sb.count() == 0) { if (logger.fineEnabled()) {
@Override public long bufferSize() { return getCurrent().dataSize(); }
public void testDestroy() throws IOException { set.destroy(); assertTrue(((SortedOplogSetImpl) set).isClosed()); try { set.scan(); fail(); } catch (IllegalStateException e) { } }
protected SortedOplogSetImpl createSoplogSet(String name) throws IOException { SortedOplogFactory factory = new HFileSortedOplogFactory(name, null, new SortedOplogStatistics("stats", name), new HFileStoreStatistics("storeStats", name)); Compactor compactor = new NonCompactor(name, new File(".")); return new SortedOplogSetImpl(factory, Executors.newSingleThreadExecutor(), compactor); }
@Override public byte[] firstKey() { byte[] first = stats.get(0).firstKey(); for (int i = 1; i < stats.size(); i++) { byte[] tmp = stats.get(i).firstKey(); if (getComparator().compare(first, tmp) > 0) { first = tmp; } } return first; }
private SortedBuffer<Integer> flipBuffer() { final SortedBuffer<Integer> sb; sb = getCurrent(); SortedBuffer<Integer> next = new SortedBuffer<Integer>( factory.getConfiguration(), bufferCount.incrementAndGet()); current.set(next); if (logger.fineEnabled()) { logger.fine(String.format("Switching from buffer %s to %s", sb, next)); } return sb; }
@Override protected SortedOplogSetImpl createSoplogSet(String name) throws IOException { SortedOplogFactory factory = new HFileSortedOplogFactory(name, null, new SortedOplogStatistics("stats", name), new HFileStoreStatistics("storeStats", name)); Compactor compactor = createCompactor(factory); return new SortedOplogSetImpl(factory, Executors.newSingleThreadExecutor(), compactor); }
@Override public byte[] lastKey() { byte[] last = stats.get(0).lastKey(); for (int i = 1; i < stats.size(); i++) { byte[] tmp = stats.get(i).lastKey(); if (getComparator().compare(last, tmp) < 0) { last = tmp; } } return last; }
@Override public SortedStatistics getStatistics() throws IOException { List<SortedStatistics> stats = new ArrayList<SortedStatistics>(); Collection<TrackedReference<SortedOplogReader>> soplogs; // snapshot, this is expensive rwlock.readLock().lock(); try { stats.add(getCurrent().getStatistics()); for (SortedBuffer<Integer> sb : unflushed) { stats.add(sb.getStatistics()); } soplogs = compactor.getActiveReaders(null, null); } finally { rwlock.readLock().unlock(); } for (TrackedReference<SortedOplogReader> tr : soplogs) { stats.add(tr.get().getStatistics()); } return new MergedStatistics(stats, soplogs); }
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(); }
if (getCurrent().mightContain(key)) { return true;
@Override public SortedIterator<ByteBuffer> scan( byte[] from, boolean fromInclusive, byte[] to, boolean toInclusive, boolean ascending, MetadataFilter filter) throws IOException { SerializedComparator sc = factory.getConfiguration().getComparator(); sc = ascending ? sc : ReversingSerializedComparator.reverse(sc); List<SortedIterator<ByteBuffer>> scans = new ArrayList<SortedIterator<ByteBuffer>>(); Collection<TrackedReference<SortedOplogReader>> soplogs; rwlock.readLock().lock(); try { scans.add(getCurrent().scan(from, fromInclusive, to, toInclusive, ascending, filter)); for (SortedBuffer<Integer> sb : unflushed) { scans.add(sb.scan(from, fromInclusive, to, toInclusive, ascending, filter)); } soplogs = compactor.getActiveReaders(from, to); } finally { rwlock.readLock().unlock(); } for (TrackedReference<SortedOplogReader> tr : soplogs) { scans.add(tr.get().scan(from, fromInclusive, to, toInclusive, ascending, filter)); } return new MergedIterator(sc, soplogs, scans); }
ByteBuffer val = getCurrent().read(key); if (val != null) { return val;
@Override public void put(byte[] key, byte[] value) { assert key != null; assert value != null; long start = factory.getConfiguration().getStatistics().getPut().begin(); getCurrent().put(key, value); factory.getConfiguration().getStatistics().getPut().end(value.length, start); }