Search in sources :

Example 6 with DataConsistencyStatementResult

use of herddb.model.DataConsistencyStatementResult in project herddb by diennea.

the class DBManager method createTableSpaceCheckSum.

public DataConsistencyStatementResult createTableSpaceCheckSum(TableSpaceConsistencyCheckStatement tableSpaceConsistencyCheckStatement) {
    TableSpaceManager manager = tablesSpaces.get(tableSpaceConsistencyCheckStatement.getTableSpace());
    String tableSpace = tableSpaceConsistencyCheckStatement.getTableSpace();
    List<Table> tables = manager.getAllCommittedTables();
    long _start = System.currentTimeMillis();
    for (Table table : tables) {
        AbstractTableManager tableManager = manager.getTableManager(table.name);
        if (!tableManager.isSystemTable()) {
            try {
                manager.createAndWriteTableCheksum(manager, tableSpace, tableManager.getTable().name, null);
            } catch (IOException | DataScannerException ex) {
                LOGGER.log(Level.SEVERE, "Error on check of tablespace " + tableSpace, ex);
                return new DataConsistencyStatementResult(false, "Error on check  of tablespace " + tableSpace + ":" + ex);
            }
        }
    }
    long _stop = System.currentTimeMillis();
    long tableSpace_check_duration = (_stop - _start);
    LOGGER.log(Level.INFO, "Check tablespace consistency for {0} Completed in {1} ms", new Object[] { tableSpace, tableSpace_check_duration });
    return new DataConsistencyStatementResult(true, "Check tablespace consistency for " + tableSpace + "completed in " + tableSpace_check_duration);
}
Also used : Table(herddb.model.Table) DataConsistencyStatementResult(herddb.model.DataConsistencyStatementResult) IOException(java.io.IOException) DataScannerException(herddb.model.DataScannerException)

Example 7 with DataConsistencyStatementResult

use of herddb.model.DataConsistencyStatementResult in project herddb by diennea.

the class ConsistencyCheckDuringRecoveryTest 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));
        }
    }
    try (DBManager manager1 = startDBManager("node1")) {
        // restart leader node
        manager1.waitForTablespace("t2", 10000);
    }
    try (DBManager manager1 = startDBManager("node2")) {
        // restart follower  node
        manager1.waitForTablespace("t2", 1000);
    }
    // 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 8 with DataConsistencyStatementResult

use of herddb.model.DataConsistencyStatementResult 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 9 with DataConsistencyStatementResult

use of herddb.model.DataConsistencyStatementResult 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

DataConsistencyStatementResult (herddb.model.DataConsistencyStatementResult)9 Table (herddb.model.Table)8 DBManager (herddb.core.DBManager)6 CreateTableStatement (herddb.model.commands.CreateTableStatement)6 Test (org.junit.Test)6 TableConsistencyCheckStatement (herddb.model.commands.TableConsistencyCheckStatement)5 MemoryCommitLogManager (herddb.mem.MemoryCommitLogManager)4 MemoryDataStorageManager (herddb.mem.MemoryDataStorageManager)4 MemoryMetadataStorageManager (herddb.mem.MemoryMetadataStorageManager)4 DataScannerException (herddb.model.DataScannerException)2 CreateTableSpaceStatement (herddb.model.commands.CreateTableSpaceStatement)2 SystemInstrumentation (herddb.utils.SystemInstrumentation)2 IOException (java.io.IOException)2 HashSet (java.util.HashSet)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 RunningStatementInfo (herddb.core.RunningStatementInfo)1 RunningStatementsStats (herddb.core.RunningStatementsStats)1 DDLStatementExecutionResult (herddb.model.DDLStatementExecutionResult)1 DMLStatementExecutionResult (herddb.model.DMLStatementExecutionResult)1 DuplicatePrimaryKeyException (herddb.model.DuplicatePrimaryKeyException)1