Search in sources :

Example 1 with DDLStatementExecutionResult

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

the class DBManager method createTableSpace.

private StatementExecutionResult createTableSpace(CreateTableSpaceStatement createTableSpaceStatement) throws StatementExecutionException {
    TableSpace tableSpace;
    try {
        tableSpace = TableSpace.builder().leader(createTableSpaceStatement.getLeaderId()).name(createTableSpaceStatement.getTableSpace()).replicas(createTableSpaceStatement.getReplicas()).expectedReplicaCount(createTableSpaceStatement.getExpectedReplicaCount()).maxLeaderInactivityTime(createTableSpaceStatement.getMaxleaderinactivitytime()).build();
    } catch (IllegalArgumentException invalid) {
        throw new StatementExecutionException("invalid CREATE TABLESPACE statement: " + invalid.getMessage(), invalid);
    }
    try {
        metadataStorageManager.registerTableSpace(tableSpace);
        triggerActivator(ActivatorRunRequest.FULL);
        if (createTableSpaceStatement.getWaitForTableSpaceTimeout() > 0) {
            boolean okWait = false;
            int poolTime = 100;
            if (metadataStorageManager instanceof MemoryMetadataStorageManager || metadataStorageManager instanceof FileMetadataStorageManager) {
                poolTime = 5;
            }
            LOGGER.log(Level.SEVERE, "waiting for  " + tableSpace.name + ", uuid " + tableSpace.uuid + ", to be up withint " + createTableSpaceStatement.getWaitForTableSpaceTimeout() + " ms");
            final int timeout = createTableSpaceStatement.getWaitForTableSpaceTimeout();
            for (int i = 0; i < timeout; i += poolTime) {
                List<TableSpaceReplicaState> replicateStates = metadataStorageManager.getTableSpaceReplicaState(tableSpace.uuid);
                for (TableSpaceReplicaState ts : replicateStates) {
                    LOGGER.log(Level.SEVERE, "waiting for  " + tableSpace.name + ", uuid " + tableSpace.uuid + ", to be up, replica state node: " + ts.nodeId + ", state: " + TableSpaceReplicaState.modeToSQLString(ts.mode) + ", ts " + new java.sql.Timestamp(ts.timestamp));
                    if (ts.mode == TableSpaceReplicaState.MODE_LEADER) {
                        okWait = true;
                        break;
                    }
                }
                if (okWait) {
                    break;
                }
                Thread.sleep(poolTime);
            }
            if (!okWait) {
                throw new StatementExecutionException("tablespace " + tableSpace.name + ", uuid " + tableSpace.uuid + " has been created but leader " + tableSpace.leaderId + " did not start within " + createTableSpaceStatement.getWaitForTableSpaceTimeout() + " ms");
            }
        }
        return new DDLStatementExecutionResult(TransactionContext.NOTRANSACTION_ID);
    } catch (StatementExecutionException err) {
        throw err;
    } catch (Exception err) {
        throw new StatementExecutionException(err);
    }
}
Also used : TableSpace(herddb.model.TableSpace) FileMetadataStorageManager(herddb.file.FileMetadataStorageManager) 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) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) TableSpaceDoesNotExistException(herddb.model.TableSpaceDoesNotExistException) TableSpaceReplicaState(herddb.model.TableSpaceReplicaState) MemoryMetadataStorageManager(herddb.mem.MemoryMetadataStorageManager)

Example 2 with DDLStatementExecutionResult

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

the class DBManager method dropTableSpace.

private StatementExecutionResult dropTableSpace(DropTableSpaceStatement dropTableSpaceStatement) throws StatementExecutionException {
    try {
        TableSpace previous = metadataStorageManager.describeTableSpace(dropTableSpaceStatement.getTableSpace());
        if (previous == null) {
            throw new TableSpaceDoesNotExistException(dropTableSpaceStatement.getTableSpace());
        }
        metadataStorageManager.dropTableSpace(dropTableSpaceStatement.getTableSpace(), previous);
        triggerActivator(ActivatorRunRequest.TABLESPACEMANAGEMENT);
        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) 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) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) TableSpaceDoesNotExistException(herddb.model.TableSpaceDoesNotExistException) StatementExecutionException(herddb.model.StatementExecutionException)

Example 3 with DDLStatementExecutionResult

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

the class TableSpaceManager method alterTable.

private StatementExecutionResult alterTable(AlterTableStatement alterTableStatement, TransactionContext transactionContext) throws TableDoesNotExistException, StatementExecutionException {
    generalLock.writeLock().lock();
    try {
        if (transactionContext.transactionId > 0) {
            throw new StatementExecutionException("ALTER TABLE cannot be executed inside a transaction (txid=" + transactionContext.transactionId + ")");
        }
        AbstractTableManager tableManager = tables.get(alterTableStatement.getTable());
        if (tableManager == null) {
            throw new TableDoesNotExistException("no table " + alterTableStatement.getTable() + " in tablespace " + tableSpaceName);
        }
        Table newTable;
        try {
            newTable = tableManager.getTable().applyAlterTable(alterTableStatement);
        } catch (IllegalArgumentException error) {
            throw new StatementExecutionException(error);
        }
        LogEntry entry = LogEntryFactory.alterTable(newTable, null);
        try {
            CommitLogResult pos = log.log(entry, entry.transactionId <= 0);
            apply(pos, entry, false);
        } catch (Exception err) {
            throw new StatementExecutionException(err);
        }
        return new DDLStatementExecutionResult(transactionContext.transactionId);
    } finally {
        generalLock.writeLock().unlock();
    }
}
Also used : TableDoesNotExistException(herddb.model.TableDoesNotExistException) Table(herddb.model.Table) CommitLogResult(herddb.log.CommitLogResult) DDLStatementExecutionResult(herddb.model.DDLStatementExecutionResult) StatementExecutionException(herddb.model.StatementExecutionException) LogEntry(herddb.log.LogEntry) DumpedLogEntry(herddb.backup.DumpedLogEntry) HDBException(herddb.client.HDBException) IndexAlreadyExistsException(herddb.model.IndexAlreadyExistsException) LogNotAvailableException(herddb.log.LogNotAvailableException) ClientSideMetadataProviderException(herddb.client.ClientSideMetadataProviderException) IndexDoesNotExistException(herddb.model.IndexDoesNotExistException) FullRecoveryNeededException(herddb.log.FullRecoveryNeededException) TableAlreadyExistsException(herddb.model.TableAlreadyExistsException) TimeoutException(java.util.concurrent.TimeoutException) DataStorageManagerException(herddb.storage.DataStorageManagerException) TableDoesNotExistException(herddb.model.TableDoesNotExistException) DDLException(herddb.model.DDLException) StatementExecutionException(herddb.model.StatementExecutionException) EOFException(java.io.EOFException) MetadataStorageManagerException(herddb.metadata.MetadataStorageManagerException)

Example 4 with DDLStatementExecutionResult

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

the class TableSpaceManager method dropIndex.

private StatementExecutionResult dropIndex(DropIndexStatement statement, Transaction transaction) throws StatementExecutionException {
    generalLock.writeLock().lock();
    try {
        if (!indexes.containsKey(statement.getIndexName())) {
            if (statement.isIfExists()) {
                return new DDLStatementExecutionResult(transaction != null ? transaction.transactionId : 0);
            }
            throw new IndexDoesNotExistException("index " + statement.getIndexName() + " does not exist " + statement.getIndexName() + " on tableSpace " + statement.getTableSpace());
        }
        if (transaction != null && transaction.isIndexDropped(statement.getIndexName())) {
            if (statement.isIfExists()) {
                return new DDLStatementExecutionResult(transaction.transactionId);
            }
            throw new IndexDoesNotExistException("index does not exist " + statement.getIndexName() + " on tableSpace " + statement.getTableSpace());
        }
        LogEntry entry = LogEntryFactory.dropIndex(statement.getIndexName(), transaction);
        CommitLogResult pos;
        try {
            pos = log.log(entry, entry.transactionId <= 0);
        } catch (LogNotAvailableException ex) {
            throw new StatementExecutionException(ex);
        }
        apply(pos, entry, false);
        return new DDLStatementExecutionResult(entry.transactionId);
    } catch (DataStorageManagerException err) {
        throw new StatementExecutionException(err);
    } finally {
        generalLock.writeLock().unlock();
    }
}
Also used : DataStorageManagerException(herddb.storage.DataStorageManagerException) IndexDoesNotExistException(herddb.model.IndexDoesNotExistException) DDLStatementExecutionResult(herddb.model.DDLStatementExecutionResult) CommitLogResult(herddb.log.CommitLogResult) LogEntry(herddb.log.LogEntry) DumpedLogEntry(herddb.backup.DumpedLogEntry) StatementExecutionException(herddb.model.StatementExecutionException) LogNotAvailableException(herddb.log.LogNotAvailableException)

Example 5 with DDLStatementExecutionResult

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

the class TableSpaceManager method createIndex.

private StatementExecutionResult createIndex(CreateIndexStatement statement, Transaction transaction) throws StatementExecutionException {
    generalLock.writeLock().lock();
    try {
        if (indexes.containsKey(statement.getIndexefinition().name)) {
            throw new IndexAlreadyExistsException(statement.getIndexefinition().name);
        }
        LogEntry entry = LogEntryFactory.createIndex(statement.getIndexefinition(), transaction);
        CommitLogResult pos;
        try {
            pos = log.log(entry, entry.transactionId <= 0);
        } catch (LogNotAvailableException ex) {
            throw new StatementExecutionException(ex);
        }
        apply(pos, entry, false);
        return new DDLStatementExecutionResult(entry.transactionId);
    } catch (DataStorageManagerException err) {
        throw new StatementExecutionException(err);
    } finally {
        generalLock.writeLock().unlock();
    }
}
Also used : DataStorageManagerException(herddb.storage.DataStorageManagerException) IndexAlreadyExistsException(herddb.model.IndexAlreadyExistsException) CommitLogResult(herddb.log.CommitLogResult) DDLStatementExecutionResult(herddb.model.DDLStatementExecutionResult) LogEntry(herddb.log.LogEntry) DumpedLogEntry(herddb.backup.DumpedLogEntry) StatementExecutionException(herddb.model.StatementExecutionException) LogNotAvailableException(herddb.log.LogNotAvailableException)

Aggregations

DDLStatementExecutionResult (herddb.model.DDLStatementExecutionResult)9 StatementExecutionException (herddb.model.StatementExecutionException)9 LogNotAvailableException (herddb.log.LogNotAvailableException)8 DataStorageManagerException (herddb.storage.DataStorageManagerException)8 DumpedLogEntry (herddb.backup.DumpedLogEntry)5 CommitLogResult (herddb.log.CommitLogResult)5 LogEntry (herddb.log.LogEntry)5 MetadataStorageManagerException (herddb.metadata.MetadataStorageManagerException)4 DDLException (herddb.model.DDLException)4 DataScannerException (herddb.model.DataScannerException)4 NotLeaderException (herddb.model.NotLeaderException)4 IndexAlreadyExistsException (herddb.model.IndexAlreadyExistsException)3 TableSpace (herddb.model.TableSpace)3 TableSpaceDoesNotExistException (herddb.model.TableSpaceDoesNotExistException)3 IndexDoesNotExistException (herddb.model.IndexDoesNotExistException)2 Table (herddb.model.Table)2 TableAlreadyExistsException (herddb.model.TableAlreadyExistsException)2 TableDoesNotExistException (herddb.model.TableDoesNotExistException)2 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)2 ClientSideMetadataProviderException (herddb.client.ClientSideMetadataProviderException)1