Search in sources :

Example 6 with TableConsistencyCheckStatement

use of herddb.model.commands.TableConsistencyCheckStatement in project herddb by diennea.

the class MultiNodeConsistencyCheckTest method consistencyCheckReplicaTest.

@Test
public void consistencyCheckReplicaTest() throws Exception {
    final AtomicInteger callCount = new AtomicInteger();
    SystemInstrumentation.addListener(new SystemInstrumentation.SingleInstrumentationPointListener("createChecksum") {

        @Override
        public void acceptSingle(Object... args) throws Exception {
            callCount.incrementAndGet();
        }
    });
    try (DBManager manager1 = startDBManager("node1")) {
        manager1.executeStatement(new CreateTableSpaceStatement(tableSpaceName, new HashSet<>(Arrays.asList("node1", "node2")), "node1", 1, 0, 0), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
        manager1.waitForTablespace(tableSpaceName, 10000, true);
        try (DBManager manager2 = startDBManager("node2")) {
            manager2.waitForTablespace(tableSpaceName, 10000, false);
            Table table = Table.builder().tablespace(tableSpaceName).name(tableName).column("id", ColumnTypes.STRING).column("name", ColumnTypes.BOOLEAN).primaryKey("id").build();
            CreateTableStatement st = new CreateTableStatement(table);
            manager1.executeStatement(st, StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
            manager1.waitForTable(tableSpaceName, tableName, 10000, true);
            execute(manager1, "INSERT INTO t2.table1 (id,name) values (?,?)", Arrays.asList("1", true));
            execute(manager1, "INSERT INTO t2.table1 (id,name) values (?,?)", Arrays.asList("2", false));
            manager2.waitForTable(tableSpaceName, tableName, 10000, false);
            TableConsistencyCheckStatement statement = new TableConsistencyCheckStatement("table1", "t2");
            DataConsistencyStatementResult result = manager1.createTableCheckSum(statement, null);
            assertTrue("Consistency check replicated test ", result.getOk());
            // The follower is always back 1, I make an entry to make him apply consistency log
            execute(manager1, "INSERT INTO t2.table1 (id,name) values (?,?)", Arrays.asList("3", false));
        }
    }
    // Expected 2 call for createChecksum (node1 and node2)
    assertEquals(2, callCount.get());
}
Also used : Table(herddb.model.Table) CreateTableStatement(herddb.model.commands.CreateTableStatement) DataConsistencyStatementResult(herddb.model.DataConsistencyStatementResult) CreateTableSpaceStatement(herddb.model.commands.CreateTableSpaceStatement) DBManager(herddb.core.DBManager) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) SystemInstrumentation(herddb.utils.SystemInstrumentation) HashSet(java.util.HashSet) TableConsistencyCheckStatement(herddb.model.commands.TableConsistencyCheckStatement) Test(org.junit.Test)

Example 7 with TableConsistencyCheckStatement

use of herddb.model.commands.TableConsistencyCheckStatement in project herddb by diennea.

the class DataConsistencyCheckTest method tableConsistencyCheckWithNullValue.

@Test
public void tableConsistencyCheckWithNullValue() throws Exception {
    String tableSpaceName = "tblspace1";
    String tableName = "t1";
    try (DBManager manager = new DBManager("localhost", new MemoryMetadataStorageManager(), new MemoryDataStorageManager(), new MemoryCommitLogManager(), null, null)) {
        manager.start();
        assertTrue(manager.waitForBootOfLocalTablespaces(10000));
        execute(manager, "CREATE TABLESPACE 'tblspace1'", Collections.emptyList());
        manager.waitForTablespace("tblspace1", 10000);
        Table table = Table.builder().tablespace(tableSpaceName).name(tableName).column("k1", ColumnTypes.STRING).column("n1", ColumnTypes.INTEGER).column("s1", ColumnTypes.STRING).primaryKey("k1").build();
        CreateTableStatement st = new CreateTableStatement(table);
        manager.executeStatement(st, StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
        execute(manager, "INSERT INTO " + tableSpaceName + "." + tableName + " (k1,n1 ,s1) values (?,?,?)", Arrays.asList("1", null, "b"));
        execute(manager, "INSERT INTO " + tableSpaceName + "." + tableName + " (k1,n1 ,s1) values (?,?,?)", Arrays.asList("2", null, "b"));
        TableConsistencyCheckStatement statement = new TableConsistencyCheckStatement(tableName, tableSpaceName);
        DataConsistencyStatementResult result = manager.createTableCheckSum(statement, null);
        assertTrue("Check table with null value ", result.getOk());
    }
}
Also used : DBManager(herddb.core.DBManager) Table(herddb.model.Table) MemoryDataStorageManager(herddb.mem.MemoryDataStorageManager) MemoryCommitLogManager(herddb.mem.MemoryCommitLogManager) CreateTableStatement(herddb.model.commands.CreateTableStatement) DataConsistencyStatementResult(herddb.model.DataConsistencyStatementResult) MemoryMetadataStorageManager(herddb.mem.MemoryMetadataStorageManager) TableConsistencyCheckStatement(herddb.model.commands.TableConsistencyCheckStatement) Test(org.junit.Test)

Aggregations

TableConsistencyCheckStatement (herddb.model.commands.TableConsistencyCheckStatement)7 Table (herddb.model.Table)6 DBManager (herddb.core.DBManager)5 DataConsistencyStatementResult (herddb.model.DataConsistencyStatementResult)5 CreateTableStatement (herddb.model.commands.CreateTableStatement)5 Test (org.junit.Test)5 MemoryCommitLogManager (herddb.mem.MemoryCommitLogManager)3 MemoryDataStorageManager (herddb.mem.MemoryDataStorageManager)3 MemoryMetadataStorageManager (herddb.mem.MemoryMetadataStorageManager)3 StatementExecutionException (herddb.model.StatementExecutionException)2 CreateTableSpaceStatement (herddb.model.commands.CreateTableSpaceStatement)2 SystemInstrumentation (herddb.utils.SystemInstrumentation)2 HashSet (java.util.HashSet)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 RecordSerializer (herddb.codec.RecordSerializer)1 AbstractTableManager (herddb.core.AbstractTableManager)1 DataPageMetaData (herddb.core.PageSet.DataPageMetaData)1 TableSpaceManager (herddb.core.TableSpaceManager)1 TableManagerStats (herddb.core.stats.TableManagerStats)1 IndexOperation (herddb.index.IndexOperation)1