use of herddb.model.commands.TableSpaceConsistencyCheckStatement in project herddb by diennea.
the class DataConsistencyCheckTest method tableSpaceConsistencyCheck.
@Test
public void tableSpaceConsistencyCheck() throws Exception {
String tableSpaceName = "tblspace1";
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);
manager.waitForTablespace(tableSpaceName, 10000, false);
Table table = Table.builder().tablespace(tableSpaceName).name("t1").column("id", ColumnTypes.STRING).column("name", ColumnTypes.STRING).primaryKey("id").build();
Table table2 = Table.builder().tablespace(tableSpaceName).name("t2").column("id", ColumnTypes.STRING).column("name", ColumnTypes.BOOLEAN).primaryKey("id").build();
CreateTableStatement st = new CreateTableStatement(table);
manager.executeStatement(st, StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
CreateTableStatement st2 = new CreateTableStatement(table2);
manager.executeStatement(st2, StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
execute(manager, "INSERT INTO tblspace1.t1 (id,name) values (?,?)", Arrays.asList("1", true));
execute(manager, "INSERT INTO tblspace1.t1 (id,name) values (?,?)", Arrays.asList("2", false));
execute(manager, "INSERT INTO tblspace1.t2 (id,name) values (?,?)", Arrays.asList("1", true));
execute(manager, "INSERT INTO tblspace1.t2 (id,name) values (?,?)", Arrays.asList("2", false));
TableSpaceConsistencyCheckStatement statement = new TableSpaceConsistencyCheckStatement(tableSpaceName);
DataConsistencyStatementResult result = manager.createTableSpaceCheckSum(statement);
assertTrue("Check tableSpace ", result.getOk());
}
}
use of herddb.model.commands.TableSpaceConsistencyCheckStatement in project herddb by diennea.
the class JSQLParserPlanner method queryConsistencyCheckStatement.
public Statement queryConsistencyCheckStatement(String query) {
if (query.startsWith(TABLESPACE_CONSISTENCY_COMMAND)) {
String tableSpace = query.substring(query.substring(0, 26).length()).replace("\'", "");
TableSpaceManager tableSpaceManager = manager.getTableSpaceManager(tableSpace.trim());
if (tableSpaceManager == null) {
throw new TableSpaceDoesNotExistException(String.format("Tablespace %s does not exist.", tableSpace));
}
return new TableSpaceConsistencyCheckStatement(tableSpace.trim());
} else {
throw new StatementExecutionException(String.format("Incorrect Syntax for tablespaceconsistencycheck"));
}
}
use of herddb.model.commands.TableSpaceConsistencyCheckStatement in project herddb by diennea.
the class DBManager method executeStatementAsync.
public CompletableFuture<StatementExecutionResult> executeStatementAsync(Statement statement, StatementEvaluationContext context, TransactionContext transactionContext) {
context.setDefaultTablespace(statement.getTableSpace());
context.setManager(this);
context.setTransactionContext(transactionContext);
// LOGGER.log(Level.SEVERE, "executeStatement {0}", new Object[]{statement});
String tableSpace = statement.getTableSpace();
if (tableSpace == null) {
return Futures.exception(new StatementExecutionException("invalid null tableSpace"));
}
if (statement instanceof CreateTableSpaceStatement) {
if (transactionContext.transactionId > 0) {
return Futures.exception(new StatementExecutionException("CREATE TABLESPACE cannot be issued inside a transaction"));
}
return CompletableFuture.completedFuture(createTableSpace((CreateTableSpaceStatement) statement));
}
if (statement instanceof AlterTableSpaceStatement) {
if (transactionContext.transactionId > 0) {
return Futures.exception(new StatementExecutionException("ALTER TABLESPACE cannot be issued inside a transaction"));
}
return CompletableFuture.completedFuture(alterTableSpace((AlterTableSpaceStatement) statement));
}
if (statement instanceof DropTableSpaceStatement) {
if (transactionContext.transactionId > 0) {
return Futures.exception(new StatementExecutionException("DROP TABLESPACE cannot be issued inside a transaction"));
}
return CompletableFuture.completedFuture(dropTableSpace((DropTableSpaceStatement) statement));
}
if (statement instanceof TableSpaceConsistencyCheckStatement) {
if (transactionContext.transactionId > 0) {
return Futures.exception(new StatementExecutionException("TABLESPACECONSISTENCYCHECK cannot be issue inside a transaction"));
}
return CompletableFuture.completedFuture(createTableSpaceCheckSum((TableSpaceConsistencyCheckStatement) statement));
}
TableSpaceManager manager = tablesSpaces.get(tableSpace);
if (manager == null) {
return Futures.exception(new NotLeaderException("No such tableSpace " + tableSpace + " here (at " + nodeId + "). " + "Maybe the server is starting "));
}
if (errorIfNotLeader && !manager.isLeader()) {
return Futures.exception(new NotLeaderException("node " + nodeId + " is not leader for tableSpace " + tableSpace));
}
CompletableFuture<StatementExecutionResult> res = manager.executeStatementAsync(statement, context, transactionContext);
if (statement instanceof DDLStatement) {
res.whenComplete((s, err) -> {
planner.clearCache();
});
planner.clearCache();
}
// });
return res;
}
Aggregations