use of org.voltcore.utils.DBBPool.BBContainer in project voltdb by VoltDB.
the class TestPersistentBinaryDeque method testCloseEmptyShouldNotDelete.
@Test
public void testCloseEmptyShouldNotDelete() throws Exception {
System.out.println("Running testCloseEmptyShouldNotDelete");
TreeSet<String> listing = getSortedDirectoryListing();
assertEquals(listing.size(), 1);
m_pbd.close();
listing = getSortedDirectoryListing();
assertEquals(listing.size(), 1);
m_pbd = new PersistentBinaryDeque(TEST_NONCE, TEST_DIR, logger);
listing = getSortedDirectoryListing();
assertEquals(listing.size(), 1);
m_pbd.parseAndTruncate(new BinaryDequeTruncator() {
@Override
public TruncatorResponse parse(BBContainer bbc) {
fail();
return null;
}
});
for (int ii = 0; ii < 96; ii++) {
m_pbd.offer(DBBPool.wrapBB(getFilledBuffer(ii)));
}
BinaryDequeReader reader = m_pbd.openForRead(CURSOR_ID);
for (long ii = 0; ii < 96; ii++) {
BBContainer cont = reader.poll(PersistentBinaryDeque.UNSAFE_CONTAINER_FACTORY);
try {
assertNotNull(cont);
assertEquals(cont.b().remaining(), 1024 * 1024 * 2);
while (cont.b().remaining() > 15) {
assertEquals(ii, cont.b().getLong());
cont.b().getLong();
}
} catch (Throwable t) {
System.err.println("Something threw");
t.printStackTrace();
throw t;
} finally {
cont.discard();
}
}
}
use of org.voltcore.utils.DBBPool.BBContainer in project voltdb by VoltDB.
the class TestPersistentBinaryDeque method testDontCloseReadSegment.
@Test
public void testDontCloseReadSegment() throws Exception {
System.out.println("Running testOfferPollOfferMoreThanPoll");
BinaryDequeReader reader = m_pbd.openForRead(CURSOR_ID);
assertNull(reader.poll(PersistentBinaryDeque.UNSAFE_CONTAINER_FACTORY));
final int total = 100;
//Make sure a single file with the appropriate data is created
for (int i = 0; i < 5; i++) {
m_pbd.offer(defaultContainer());
}
assertEquals(1, TEST_DIR.listFiles().length);
// Read one buffer from the segment so that it's considered being polled from.
reader.poll(PersistentBinaryDeque.UNSAFE_CONTAINER_FACTORY).discard();
for (int i = 5; i < total; i++) {
m_pbd.offer(defaultContainer());
}
File[] files = TEST_DIR.listFiles();
assertEquals(3, files.length);
Set<String> actualFiles = Sets.newHashSet();
for (File f : files) {
actualFiles.add(f.getName());
}
Set<String> expectedFiles = Sets.newHashSet();
for (int i = 0; i < 3; i++) {
expectedFiles.add("pbd_nonce." + i + ".pbd");
}
Assert.assertEquals(expectedFiles, actualFiles);
//Now make sure the current write file is stolen and a new write file created
for (int i = 1; i < total; i++) {
BBContainer retval = reader.poll(PersistentBinaryDeque.UNSAFE_CONTAINER_FACTORY);
retval.discard();
}
}
use of org.voltcore.utils.DBBPool.BBContainer in project voltdb by VoltDB.
the class TestExecutionEngine method testStreamTables.
public void testStreamTables() throws Exception {
sourceEngine.loadCatalog(0, m_catalog.serialize());
// Each EE needs its own thread for correct initialization.
final AtomicReference<ExecutionEngine> destinationEngine = new AtomicReference<ExecutionEngine>();
final byte[] configBytes = LegacyHashinator.getConfigureBytes(1);
Thread destEEThread = new Thread() {
@Override
public void run() {
destinationEngine.set(new ExecutionEngineJNI(CLUSTER_ID, NODE_ID, 0, 0, "", 0, 64 * 1024, 100, new HashinatorConfig(HashinatorType.LEGACY, configBytes, 0, 0), false));
}
};
destEEThread.start();
destEEThread.join();
destinationEngine.get().loadCatalog(0, m_catalog.serialize());
int WAREHOUSE_TABLEID = warehouseTableId(m_catalog);
int STOCK_TABLEID = stockTableId(m_catalog);
loadTestTables(sourceEngine, m_catalog);
sourceEngine.activateTableStream(WAREHOUSE_TABLEID, TableStreamType.RECOVERY, Long.MAX_VALUE, new SnapshotPredicates(-1).toBytes());
sourceEngine.activateTableStream(STOCK_TABLEID, TableStreamType.RECOVERY, Long.MAX_VALUE, new SnapshotPredicates(-1).toBytes());
final BBContainer origin = DBBPool.allocateDirect(1024 * 1024 * 2);
origin.b().clear();
final BBContainer container = new BBContainer(origin.b()) {
@Override
public void discard() {
checkDoubleFree();
origin.discard();
}
};
try {
List<BBContainer> output = new ArrayList<BBContainer>();
output.add(container);
int serialized = sourceEngine.tableStreamSerializeMore(WAREHOUSE_TABLEID, TableStreamType.RECOVERY, output).getSecond()[0];
assertTrue(serialized > 0);
container.b().limit(serialized);
destinationEngine.get().processRecoveryMessage(container.b(), container.address());
serialized = sourceEngine.tableStreamSerializeMore(WAREHOUSE_TABLEID, TableStreamType.RECOVERY, output).getSecond()[0];
assertEquals(5, serialized);
assertEquals(RecoveryMessageType.Complete.ordinal(), container.b().get());
assertEquals(sourceEngine.tableHashCode(WAREHOUSE_TABLEID), destinationEngine.get().tableHashCode(WAREHOUSE_TABLEID));
container.b().clear();
serialized = sourceEngine.tableStreamSerializeMore(STOCK_TABLEID, TableStreamType.RECOVERY, output).getSecond()[0];
assertTrue(serialized > 0);
container.b().limit(serialized);
destinationEngine.get().processRecoveryMessage(container.b(), container.address());
serialized = sourceEngine.tableStreamSerializeMore(STOCK_TABLEID, TableStreamType.RECOVERY, output).getSecond()[0];
assertEquals(5, serialized);
assertEquals(RecoveryMessageType.Complete.ordinal(), container.b().get());
assertEquals(STOCK_TABLEID, container.b().getInt());
assertEquals(sourceEngine.tableHashCode(STOCK_TABLEID), destinationEngine.get().tableHashCode(STOCK_TABLEID));
} finally {
container.discard();
}
}
use of org.voltcore.utils.DBBPool.BBContainer in project voltdb by VoltDB.
the class TestExecutionEngine method testStreamIndex.
public void testStreamIndex() throws Exception {
sourceEngine.loadCatalog(0, m_catalog.serialize());
// Each EE needs its own thread for correct initialization.
final AtomicReference<ExecutionEngine> destinationEngine = new AtomicReference<ExecutionEngine>();
final byte[] configBytes = LegacyHashinator.getConfigureBytes(1);
Thread destEEThread = new Thread() {
@Override
public void run() {
destinationEngine.set(new ExecutionEngineJNI(CLUSTER_ID, NODE_ID, 0, 0, "", 0, 64 * 1024, 100, new HashinatorConfig(HashinatorType.LEGACY, configBytes, 0, 0), false));
}
};
destEEThread.start();
destEEThread.join();
destinationEngine.get().loadCatalog(0, m_catalog.serialize());
int STOCK_TABLEID = stockTableId(m_catalog);
loadTestTables(sourceEngine, m_catalog);
SnapshotPredicates predicates = new SnapshotPredicates(-1);
predicates.addPredicate(new HashRangeExpressionBuilder().put(0x00000000, 0x7fffffff).build(0), true);
// Build the index
sourceEngine.activateTableStream(STOCK_TABLEID, TableStreamType.ELASTIC_INDEX, Long.MAX_VALUE, predicates.toBytes());
// Humor serializeMore() by providing a buffer, even though it's not used.
final BBContainer origin = DBBPool.allocateDirect(1024 * 1024 * 2);
origin.b().clear();
BBContainer container = new BBContainer(origin.b()) {
@Override
public void discard() {
checkDoubleFree();
origin.discard();
}
};
try {
List<BBContainer> output = new ArrayList<BBContainer>();
output.add(container);
assertEquals(0, sourceEngine.tableStreamSerializeMore(STOCK_TABLEID, TableStreamType.ELASTIC_INDEX, output).getSecond()[0]);
} finally {
container.discard();
}
}
use of org.voltcore.utils.DBBPool.BBContainer in project voltdb by VoltDB.
the class SnapshotSiteProcessor method getOutputBuffers.
/**
* Create an output buffer for each task.
* @return null if there aren't enough buffers left in the pool.
*/
private List<BBContainer> getOutputBuffers(Collection<SnapshotTableTask> tableTasks, boolean noSchedule) {
final int desired = tableTasks.size();
while (true) {
int available = m_availableSnapshotBuffers.get();
//Limit the number of buffers used concurrently
if (desired > available) {
return null;
}
if (m_availableSnapshotBuffers.compareAndSet(available, available - desired))
break;
}
List<BBContainer> outputBuffers = new ArrayList<BBContainer>(tableTasks.size());
for (int ii = 0; ii < tableTasks.size(); ii++) {
final BBContainer origin = DBBPool.allocateDirectAndPool(m_snapshotBufferLength);
outputBuffers.add(createNewBuffer(origin, noSchedule));
}
return outputBuffers;
}
Aggregations