Search in sources :

Example 1 with SnapshotPredicates

use of org.voltdb.sysprocs.saverestore.SnapshotPredicates 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();
    }
}
Also used : HashinatorConfig(org.voltdb.TheHashinator.HashinatorConfig) SnapshotPredicates(org.voltdb.sysprocs.saverestore.SnapshotPredicates) ArrayList(java.util.ArrayList) BBContainer(org.voltcore.utils.DBBPool.BBContainer) AtomicReference(java.util.concurrent.atomic.AtomicReference)

Example 2 with SnapshotPredicates

use of org.voltdb.sysprocs.saverestore.SnapshotPredicates 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();
    }
}
Also used : HashinatorConfig(org.voltdb.TheHashinator.HashinatorConfig) ArrayList(java.util.ArrayList) AtomicReference(java.util.concurrent.atomic.AtomicReference) SnapshotPredicates(org.voltdb.sysprocs.saverestore.SnapshotPredicates) HashRangeExpressionBuilder(org.voltdb.expressions.HashRangeExpressionBuilder) BBContainer(org.voltcore.utils.DBBPool.BBContainer)

Example 3 with SnapshotPredicates

use of org.voltdb.sysprocs.saverestore.SnapshotPredicates in project voltdb by VoltDB.

the class SnapshotSiteProcessor method makeTablesAndPredicatesToSnapshot.

private Map<Integer, byte[]> makeTablesAndPredicatesToSnapshot(Collection<SnapshotTableTask> tasks) {
    Map<Integer, SnapshotPredicates> tablesAndPredicates = Maps.newHashMap();
    Map<Integer, byte[]> predicateBytes = Maps.newHashMap();
    for (SnapshotTableTask task : tasks) {
        SNAP_LOG.debug("Examining SnapshotTableTask: " + task);
        // Add the task to the task list for the given table
        m_snapshotTableTasks.put(task.m_table.getRelativeIndex(), task);
        // Make sure there is a predicate object for each table, the predicate could contain
        // empty expressions. So activateTableStream() doesn't have to do a null check.
        SnapshotPredicates predicates = tablesAndPredicates.get(task.m_table.getRelativeIndex());
        if (predicates == null) {
            predicates = new SnapshotPredicates(task.m_table.getRelativeIndex());
            tablesAndPredicates.put(task.m_table.getRelativeIndex(), predicates);
        }
        predicates.addPredicate(task.m_predicate, task.m_deleteTuples);
    }
    for (Map.Entry<Integer, SnapshotPredicates> e : tablesAndPredicates.entrySet()) {
        predicateBytes.put(e.getKey(), e.getValue().toBytes());
    }
    return predicateBytes;
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) SnapshotPredicates(org.voltdb.sysprocs.saverestore.SnapshotPredicates) HashMap(java.util.HashMap) Map(java.util.Map) ImmutableMap(com.google_voltpatches.common.collect.ImmutableMap)

Aggregations

SnapshotPredicates (org.voltdb.sysprocs.saverestore.SnapshotPredicates)3 ArrayList (java.util.ArrayList)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 BBContainer (org.voltcore.utils.DBBPool.BBContainer)2 HashinatorConfig (org.voltdb.TheHashinator.HashinatorConfig)2 ImmutableMap (com.google_voltpatches.common.collect.ImmutableMap)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 HashRangeExpressionBuilder (org.voltdb.expressions.HashRangeExpressionBuilder)1