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);
}
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());
}
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());
}
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());
}
}
Aggregations