Search in sources :

Example 6 with TableSpaceDoesNotExistException

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

the class ShowCreateTableCalculator method calculateShowCreateTable.

public static TranslatedQuery calculateShowCreateTable(String query, String defaultTablespace, List<Object> parameters, DBManager manager) {
    String[] items = { "SHOW", "CREATE", "TABLE" };
    if (Arrays.stream(items).allMatch(query::contains)) {
        query = query.substring(Arrays.stream(items).collect(Collectors.joining(" ")).length()).trim();
        String tableSpace = defaultTablespace;
        String tableName;
        boolean showCreateIndex = query.contains("WITH INDEXES");
        if (showCreateIndex) {
            query = query.substring(0, query.indexOf("WITH INDEXES"));
        }
        if (query.contains(".")) {
            String[] tokens = query.split("\\.");
            tableSpace = tokens[0].trim();
            tableName = tokens[1].trim();
        } else {
            tableName = query.trim();
        }
        tableName = tableName.toLowerCase();
        TableSpaceManager tableSpaceManager = manager.getTableSpaceManager(tableSpace);
        if (tableSpaceManager == null) {
            throw new TableSpaceDoesNotExistException(String.format("Tablespace %s does not exist.", tableSpace));
        }
        AbstractTableManager tableManager = tableSpaceManager.getTableManager(tableName);
        if (tableManager == null || tableManager.getCreatedInTransaction() > 0) {
            throw new TableDoesNotExistException(String.format("Table %s does not exist.", tableName));
        }
        String showCreateResult = calculate(showCreateIndex, tableName, tableSpace, tableManager);
        ValuesOp values = new ValuesOp(manager.getNodeId(), new String[] { "tabledef" }, new Column[] { column("tabledef", ColumnTypes.STRING) }, Arrays.asList(Arrays.asList(new ConstantExpression(showCreateResult, ColumnTypes.NOTNULL_STRING))));
        ExecutionPlan executionPlan = ExecutionPlan.simple(new SQLPlannedOperationStatement(values), values);
        return new TranslatedQuery(executionPlan, new SQLStatementEvaluationContext(query, parameters, false, false));
    } else {
        throw new StatementExecutionException(String.format("Incorrect Syntax for SHOW CREATE TABLE tablespace.tablename"));
    }
}
Also used : TranslatedQuery(herddb.sql.TranslatedQuery) TableSpaceDoesNotExistException(herddb.model.TableSpaceDoesNotExistException) ConstantExpression(herddb.sql.expressions.ConstantExpression) SQLStatementEvaluationContext(herddb.sql.SQLStatementEvaluationContext) ValuesOp(herddb.model.planner.ValuesOp) StatementExecutionException(herddb.model.StatementExecutionException) SQLPlannedOperationStatement(herddb.model.commands.SQLPlannedOperationStatement) TableDoesNotExistException(herddb.model.TableDoesNotExistException) ExecutionPlan(herddb.model.ExecutionPlan) AbstractTableManager(herddb.core.AbstractTableManager) TableSpaceManager(herddb.core.TableSpaceManager)

Example 7 with TableSpaceDoesNotExistException

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

the class TableSpaceManager method createAndWriteTableCheksum.

// this method return a tableCheckSum object contain scan values (record numbers , table digest,digestType, next autoincrement value, table name, tablespacename, query used for table scan )
public TableChecksum createAndWriteTableCheksum(TableSpaceManager tableSpaceManager, String tableSpaceName, String tableName, StatementEvaluationContext context) throws IOException, DataScannerException {
    CommitLogResult pos;
    boolean lockAcquired = false;
    if (context == null) {
        context = StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT();
    }
    long lockStamp = context.getTableSpaceLock();
    LOGGER.log(Level.INFO, "Create and write table {0} checksum in tablespace ", new Object[] { tableName, tableSpaceName });
    if (lockStamp == 0) {
        lockStamp = acquireWriteLock("checkDataConsistency_" + tableName);
        context.setTableSpaceLock(lockStamp);
        lockAcquired = true;
    }
    try {
        AbstractTableManager tablemanager = tableSpaceManager.getTableManager(tableName);
        if (tableSpaceManager == null) {
            throw new TableSpaceDoesNotExistException(String.format("Tablespace %s does not exist.", tableSpaceName));
        }
        if (tablemanager == null || tablemanager.getCreatedInTransaction() > 0) {
            throw new TableDoesNotExistException(String.format("Table %s does not exist.", tablemanager));
        }
        TableChecksum scanResult = TableDataChecksum.createChecksum(tableSpaceManager.getDbmanager(), null, tableSpaceManager, tableSpaceName, tableName);
        byte[] serialize = MAPPER.writeValueAsBytes(scanResult);
        Bytes value = Bytes.from_array(serialize);
        LogEntry entry = LogEntryFactory.dataConsistency(tableName, value);
        pos = log.log(entry, false);
        apply(pos, entry, false);
        return scanResult;
    } finally {
        if (lockAcquired) {
            releaseWriteLock(context.getTableSpaceLock(), "checkDataConsistency");
            context.setTableSpaceLock(0);
        }
    }
}
Also used : TableDoesNotExistException(herddb.model.TableDoesNotExistException) Bytes(herddb.utils.Bytes) TableSpaceDoesNotExistException(herddb.model.TableSpaceDoesNotExistException) CommitLogResult(herddb.log.CommitLogResult) TableChecksum(herddb.data.consistency.TableChecksum) LogEntry(herddb.log.LogEntry) DumpedLogEntry(herddb.backup.DumpedLogEntry)

Example 8 with TableSpaceDoesNotExistException

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

the class ZookeeperMetadataStorageManager method updateTableSpaceNode.

private boolean updateTableSpaceNode(TableSpace tableSpace, int metadataStorageVersion) throws KeeperException, InterruptedException, IOException, TableSpaceDoesNotExistException {
    try {
        ensureZooKeeper().setData(tableSpacesPath + "/" + tableSpace.name.toLowerCase(), tableSpace.serialize(), metadataStorageVersion);
        notifyMetadataChanged("updateTableSpaceNode " + tableSpace + " metadataStorageVersion " + metadataStorageVersion);
        return true;
    } catch (KeeperException.BadVersionException changed) {
        return false;
    } catch (KeeperException.NoNodeException changed) {
        throw new TableSpaceDoesNotExistException(tableSpace.uuid);
    }
}
Also used : TableSpaceDoesNotExistException(herddb.model.TableSpaceDoesNotExistException) KeeperException(org.apache.zookeeper.KeeperException)

Example 9 with TableSpaceDoesNotExistException

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

the class ZookeeperMetadataStorageManager method deleteTableSpaceNode.

private boolean deleteTableSpaceNode(String tableSpaceName, int metadataStorageVersion) throws KeeperException, InterruptedException, IOException, TableSpaceDoesNotExistException {
    try {
        ensureZooKeeper().delete(tableSpacesPath + "/" + tableSpaceName.toLowerCase(), metadataStorageVersion);
        notifyMetadataChanged("deleteTableSpaceNode " + tableSpaceName + " metadataStorageVersion " + metadataStorageVersion);
        return true;
    } catch (KeeperException.BadVersionException changed) {
        return false;
    } catch (KeeperException.NoNodeException changed) {
        throw new TableSpaceDoesNotExistException(tableSpaceName);
    }
}
Also used : TableSpaceDoesNotExistException(herddb.model.TableSpaceDoesNotExistException) KeeperException(org.apache.zookeeper.KeeperException)

Example 10 with TableSpaceDoesNotExistException

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

the class DBManager method alterTableSpace.

private StatementExecutionResult alterTableSpace(AlterTableSpaceStatement alterTableSpaceStatement) throws StatementExecutionException {
    TableSpace tableSpace;
    try {
        TableSpace previous = metadataStorageManager.describeTableSpace(alterTableSpaceStatement.getTableSpace());
        if (previous == null) {
            throw new TableSpaceDoesNotExistException(alterTableSpaceStatement.getTableSpace());
        }
        try {
            tableSpace = TableSpace.builder().cloning(previous).leader(alterTableSpaceStatement.getLeaderId()).name(alterTableSpaceStatement.getTableSpace()).replicas(alterTableSpaceStatement.getReplicas()).expectedReplicaCount(alterTableSpaceStatement.getExpectedReplicaCount()).maxLeaderInactivityTime(alterTableSpaceStatement.getMaxleaderinactivitytime()).build();
        } catch (IllegalArgumentException invalid) {
            throw new StatementExecutionException("invalid ALTER TABLESPACE statement: " + invalid.getMessage(), invalid);
        }
        metadataStorageManager.updateTableSpace(tableSpace, previous);
        triggerActivator(ActivatorRunRequest.FULL);
        return new DDLStatementExecutionResult(TransactionContext.NOTRANSACTION_ID);
    } catch (Exception err) {
        throw new StatementExecutionException(err);
    }
}
Also used : TableSpace(herddb.model.TableSpace) TableSpaceDoesNotExistException(herddb.model.TableSpaceDoesNotExistException) DDLStatementExecutionResult(herddb.model.DDLStatementExecutionResult) StatementExecutionException(herddb.model.StatementExecutionException) DataStorageManagerException(herddb.storage.DataStorageManagerException) LogNotAvailableException(herddb.log.LogNotAvailableException) DDLException(herddb.model.DDLException) StatementExecutionException(herddb.model.StatementExecutionException) NotLeaderException(herddb.model.NotLeaderException) MetadataStorageManagerException(herddb.metadata.MetadataStorageManagerException) DataScannerException(herddb.model.DataScannerException) TableSpaceDoesNotExistException(herddb.model.TableSpaceDoesNotExistException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException)

Aggregations

TableSpaceDoesNotExistException (herddb.model.TableSpaceDoesNotExistException)10 StatementExecutionException (herddb.model.StatementExecutionException)6 TableSpaceManager (herddb.core.TableSpaceManager)4 TableDoesNotExistException (herddb.model.TableDoesNotExistException)4 AbstractTableManager (herddb.core.AbstractTableManager)3 TableSpace (herddb.model.TableSpace)3 LogNotAvailableException (herddb.log.LogNotAvailableException)2 MetadataStorageManagerException (herddb.metadata.MetadataStorageManagerException)2 DDLException (herddb.model.DDLException)2 DDLStatementExecutionResult (herddb.model.DDLStatementExecutionResult)2 DataScannerException (herddb.model.DataScannerException)2 NotLeaderException (herddb.model.NotLeaderException)2 DataStorageManagerException (herddb.storage.DataStorageManagerException)2 IOException (java.io.IOException)2 ExecutionException (java.util.concurrent.ExecutionException)2 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)2 KeeperException (org.apache.zookeeper.KeeperException)2 DumpedLogEntry (herddb.backup.DumpedLogEntry)1 TableChecksum (herddb.data.consistency.TableChecksum)1 CommitLogResult (herddb.log.CommitLogResult)1