Search in sources :

Example 1 with TableSpaceConsistencyCheckStatement

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());
    }
}
Also used : TableSpaceConsistencyCheckStatement(herddb.model.commands.TableSpaceConsistencyCheckStatement) 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) Test(org.junit.Test)

Example 2 with TableSpaceConsistencyCheckStatement

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"));
    }
}
Also used : TableSpaceConsistencyCheckStatement(herddb.model.commands.TableSpaceConsistencyCheckStatement) TableSpaceDoesNotExistException(herddb.model.TableSpaceDoesNotExistException) TableSpaceManager(herddb.core.TableSpaceManager) StatementExecutionException(herddb.model.StatementExecutionException)

Example 3 with TableSpaceConsistencyCheckStatement

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;
}
Also used : CreateTableSpaceStatement(herddb.model.commands.CreateTableSpaceStatement) DropTableSpaceStatement(herddb.model.commands.DropTableSpaceStatement) AlterTableSpaceStatement(herddb.model.commands.AlterTableSpaceStatement) TableSpaceConsistencyCheckStatement(herddb.model.commands.TableSpaceConsistencyCheckStatement) NotLeaderException(herddb.model.NotLeaderException) DDLStatement(herddb.model.DDLStatement) DDLStatementExecutionResult(herddb.model.DDLStatementExecutionResult) DMLStatementExecutionResult(herddb.model.DMLStatementExecutionResult) StatementExecutionResult(herddb.model.StatementExecutionResult) StatementExecutionException(herddb.model.StatementExecutionException)

Aggregations

TableSpaceConsistencyCheckStatement (herddb.model.commands.TableSpaceConsistencyCheckStatement)3 StatementExecutionException (herddb.model.StatementExecutionException)2 DBManager (herddb.core.DBManager)1 TableSpaceManager (herddb.core.TableSpaceManager)1 MemoryCommitLogManager (herddb.mem.MemoryCommitLogManager)1 MemoryDataStorageManager (herddb.mem.MemoryDataStorageManager)1 MemoryMetadataStorageManager (herddb.mem.MemoryMetadataStorageManager)1 DDLStatement (herddb.model.DDLStatement)1 DDLStatementExecutionResult (herddb.model.DDLStatementExecutionResult)1 DMLStatementExecutionResult (herddb.model.DMLStatementExecutionResult)1 DataConsistencyStatementResult (herddb.model.DataConsistencyStatementResult)1 NotLeaderException (herddb.model.NotLeaderException)1 StatementExecutionResult (herddb.model.StatementExecutionResult)1 Table (herddb.model.Table)1 TableSpaceDoesNotExistException (herddb.model.TableSpaceDoesNotExistException)1 AlterTableSpaceStatement (herddb.model.commands.AlterTableSpaceStatement)1 CreateTableSpaceStatement (herddb.model.commands.CreateTableSpaceStatement)1 CreateTableStatement (herddb.model.commands.CreateTableStatement)1 DropTableSpaceStatement (herddb.model.commands.DropTableSpaceStatement)1 Test (org.junit.Test)1