use of org.voltcore.utils.DBBPool.BBContainer in project voltdb by VoltDB.
the class FixedDBBPool method getQueue.
public BlockingQueue<DBBPool.BBContainer> getQueue(final int bufLenInBytes) {
return new BlockingQueue<BBContainer>() {
@Override
public boolean add(BBContainer bbContainer) {
throw new UnsupportedOperationException();
}
@Override
public boolean offer(BBContainer bbContainer) {
throw new UnsupportedOperationException();
}
@Override
public BBContainer remove() {
throw new UnsupportedOperationException();
}
@Override
public BBContainer poll() {
throw new UnsupportedOperationException();
}
@Override
public BBContainer element() {
throw new UnsupportedOperationException();
}
@Override
public BBContainer peek() {
throw new UnsupportedOperationException();
}
@Override
public void put(BBContainer bbContainer) throws InterruptedException {
throw new UnsupportedOperationException();
}
@Override
public boolean offer(BBContainer bbContainer, long timeout, TimeUnit unit) throws InterruptedException {
throw new UnsupportedOperationException();
}
@Override
public BBContainer take() throws InterruptedException {
final Semaphore permits = m_permits.get(bufLenInBytes);
permits.acquire();
final BBContainer origin = DBBPool.allocateDirectAndPool(bufLenInBytes);
return new BBContainer(origin.b()) {
@Override
public void discard() {
checkDoubleFree();
permits.release();
origin.discard();
}
};
}
@Override
public BBContainer poll(long timeout, TimeUnit unit) throws InterruptedException {
throw new UnsupportedOperationException();
}
@Override
public int remainingCapacity() {
throw new UnsupportedOperationException();
}
@Override
public boolean remove(Object o) {
throw new UnsupportedOperationException();
}
@Override
public boolean containsAll(Collection<?> c) {
throw new UnsupportedOperationException();
}
@Override
public boolean addAll(Collection<? extends BBContainer> c) {
throw new UnsupportedOperationException();
}
@Override
public boolean removeAll(Collection<?> c) {
throw new UnsupportedOperationException();
}
@Override
public boolean retainAll(Collection<?> c) {
throw new UnsupportedOperationException();
}
@Override
public void clear() {
throw new UnsupportedOperationException();
}
@Override
public int size() {
throw new UnsupportedOperationException();
}
@Override
public boolean isEmpty() {
throw new UnsupportedOperationException();
}
@Override
public boolean contains(Object o) {
throw new UnsupportedOperationException();
}
@Override
public Iterator<BBContainer> iterator() {
throw new UnsupportedOperationException();
}
@Override
public Object[] toArray() {
throw new UnsupportedOperationException();
}
@Override
public <T> T[] toArray(T[] a) {
throw new UnsupportedOperationException();
}
@Override
public int drainTo(Collection<? super BBContainer> c) {
throw new UnsupportedOperationException();
}
@Override
public int drainTo(Collection<? super BBContainer> c, int maxElements) {
throw new UnsupportedOperationException();
}
};
}
use of org.voltcore.utils.DBBPool.BBContainer in project voltdb by VoltDB.
the class CompressionService method decompressBuffer.
public static byte[] decompressBuffer(final ByteBuffer compressed) throws IOException {
assert (compressed.isDirect());
IOBuffers buffers = m_buffers.get();
BBContainer output = buffers.output;
final int uncompressedLength = Snappy.uncompressedLength(compressed);
final int outputCapacity = buffers.output.b().capacity();
if (outputCapacity < uncompressedLength) {
buffers.output.discard();
output = DBBPool.allocateDirect(Math.max(outputCapacity * 2, uncompressedLength));
buffers = new IOBuffers(buffers.input, output);
m_buffers.set(buffers);
}
output.b().clear();
final int actualUncompressedLength = Snappy.uncompress(compressed, output.b());
assert (uncompressedLength == actualUncompressedLength);
byte[] result = new byte[actualUncompressedLength];
output.b().get(result);
return result;
}
use of org.voltcore.utils.DBBPool.BBContainer in project voltdb by VoltDB.
the class TestPersistentBinaryDeque method testTruncator.
@Test
public void testTruncator() throws Exception {
System.out.println("Running testTruncator");
BinaryDequeReader reader = m_pbd.openForRead(CURSOR_ID);
assertNull(reader.poll(PersistentBinaryDeque.UNSAFE_CONTAINER_FACTORY));
for (int ii = 0; ii < 160; ii++) {
m_pbd.offer(DBBPool.wrapBB(getFilledBuffer(ii)));
}
m_pbd.close();
m_pbd = new PersistentBinaryDeque(TEST_NONCE, TEST_DIR, logger);
TreeSet<String> listing = getSortedDirectoryListing();
assertEquals(listing.size(), 5);
m_pbd.parseAndTruncate(new BinaryDequeTruncator() {
private long m_objectsParsed = 0;
@Override
public TruncatorResponse parse(BBContainer bbc) {
ByteBuffer b = bbc.b();
assertEquals(b.getLong(0), m_objectsParsed);
assertEquals(b.remaining(), 1024 * 1024 * 2);
if (b.getLong(0) == 45) {
b.limit(b.remaining() / 2);
return new PersistentBinaryDeque.ByteBufferTruncatorResponse(b.slice());
}
while (b.remaining() > 15) {
assertEquals(b.getLong(), m_objectsParsed);
b.getLong();
}
m_objectsParsed++;
return null;
}
});
reader = m_pbd.openForRead(CURSOR_ID);
assertEquals(95420416, reader.sizeInBytes());
listing = getSortedDirectoryListing();
assertEquals(listing.size(), 2);
for (int ii = 46; ii < 96; ii++) {
m_pbd.offer(DBBPool.wrapBB(getFilledBuffer(ii)));
}
long actualSizeInBytes = 0;
long reportedSizeInBytes = reader.sizeInBytes();
long blocksFound = 0;
BBContainer cont = null;
while ((cont = reader.poll(PersistentBinaryDeque.UNSAFE_CONTAINER_FACTORY)) != null) {
try {
ByteBuffer buffer = cont.b();
if (blocksFound == 45) {
assertEquals(buffer.remaining(), 1024 * 1024);
} else {
assertEquals(buffer.remaining(), 1024 * 1024 * 2);
}
actualSizeInBytes += buffer.remaining();
while (buffer.remaining() > 15) {
assertEquals(buffer.getLong(), blocksFound);
buffer.getLong();
}
} finally {
blocksFound++;
cont.discard();
}
}
assertEquals(actualSizeInBytes, reportedSizeInBytes);
assertEquals(blocksFound, 96);
}
use of org.voltcore.utils.DBBPool.BBContainer in project voltdb by VoltDB.
the class TestPersistentBinaryDeque method testOfferFailsWhenClosed.
@Test
public void testOfferFailsWhenClosed() throws Exception {
System.out.println("Running testOfferFailsWhenClosed");
m_pbd.close();
BBContainer cont = DBBPool.wrapBB(ByteBuffer.allocate(20));
try {
m_pbd.offer(cont);
} catch (IOException e) {
return;
} finally {
cont.discard();
}
fail();
}
use of org.voltcore.utils.DBBPool.BBContainer in project voltdb by VoltDB.
the class TestPersistentBinaryDeque method testOfferThenPushThenPoll.
@Test
public void testOfferThenPushThenPoll() throws Exception {
System.out.println("Running testOfferThenPushThenPoll");
BinaryDequeReader reader = m_pbd.openForRead(CURSOR_ID);
assertTrue(reader.isEmpty());
//Make it create two full segments
for (int ii = 0; ii < 96; ii++) {
m_pbd.offer(defaultContainer());
assertFalse(reader.isEmpty());
}
File[] files = TEST_DIR.listFiles();
assertEquals(3, files.length);
//Now create two buffers with different data to push at the front
final ByteBuffer buffer1 = getFilledBuffer(16);
final ByteBuffer buffer2 = getFilledBuffer(32);
BBContainer[] pushContainers = new BBContainer[2];
pushContainers[0] = DBBPool.dummyWrapBB(buffer1);
pushContainers[1] = DBBPool.dummyWrapBB(buffer2);
m_pbd.push(pushContainers);
//Expect this to create a single new file
TreeSet<String> names = getSortedDirectoryListing();
assertEquals(4, names.size());
assertTrue(names.first().equals("pbd_nonce.-1.pbd"));
assertTrue(names.contains("pbd_nonce.0.pbd"));
assertTrue(names.contains("pbd_nonce.1.pbd"));
assertTrue(names.last().equals("pbd_nonce.2.pbd"));
//Poll the two at the front and check that the contents are what is expected
BBContainer retval1 = reader.poll(PersistentBinaryDeque.UNSAFE_CONTAINER_FACTORY);
try {
buffer1.clear();
System.err.println(Long.toHexString(buffer1.getLong(0)) + " " + Long.toHexString(retval1.b().getLong(0)));
assertEquals(retval1.b(), buffer1);
BBContainer retval2 = reader.poll(PersistentBinaryDeque.UNSAFE_CONTAINER_FACTORY);
try {
buffer2.clear();
assertEquals(retval2.b(), buffer2);
//Expect the file for the two polled objects to still be there
//until the discard
names = getSortedDirectoryListing();
assertEquals(4, names.size());
} finally {
retval2.discard();
}
} finally {
retval1.discard();
}
names = getSortedDirectoryListing();
assertEquals(3, names.size());
assertTrue(names.first().equals("pbd_nonce.0.pbd"));
ByteBuffer defaultBuffer = defaultBuffer();
//Now poll the rest and make sure the data is correct
for (int ii = 0; ii < 96; ii++) {
defaultBuffer.clear();
BBContainer retval = reader.poll(PersistentBinaryDeque.UNSAFE_CONTAINER_FACTORY);
assertTrue(defaultBuffer.equals(retval.b()));
retval.discard();
}
assertTrue(reader.isEmpty());
//Expect just the current write segment
names = getSortedDirectoryListing();
assertEquals(1, names.size());
assertTrue(names.first().equals("pbd_nonce.2.pbd"));
}
Aggregations