Search in sources :

Example 1 with CommitLogResult

use of herddb.log.CommitLogResult 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 2 with CommitLogResult

use of herddb.log.CommitLogResult 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 3 with CommitLogResult

use of herddb.log.CommitLogResult in project herddb by diennea.

the class TableSpaceManager method beginTransaction.

private StatementExecutionResult beginTransaction() throws StatementExecutionException {
    long id = newTransactionId.incrementAndGet();
    LogEntry entry = LogEntryFactory.beginTransaction(id);
    CommitLogResult pos;
    generalLock.readLock().lock();
    try {
        pos = log.log(entry, false);
        apply(pos, entry, false);
        return new TransactionResult(id, TransactionResult.OutcomeType.BEGIN);
    } catch (Exception err) {
        throw new StatementExecutionException(err);
    } finally {
        generalLock.readLock().unlock();
    }
}
Also used : TransactionResult(herddb.model.TransactionResult) CommitLogResult(herddb.log.CommitLogResult) 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) StatementExecutionException(herddb.model.StatementExecutionException)

Example 4 with CommitLogResult

use of herddb.log.CommitLogResult in project herddb by diennea.

the class TableSpaceManager method commitTransaction.

private StatementExecutionResult commitTransaction(CommitTransactionStatement commitTransactionStatement) throws StatementExecutionException {
    long txId = commitTransactionStatement.getTransactionId();
    LogEntry entry = LogEntryFactory.commitTransaction(txId);
    generalLock.readLock().lock();
    try {
        Transaction tx = transactions.get(txId);
        if (tx == null) {
            throw new StatementExecutionException("no such transaction " + commitTransactionStatement.getTransactionId());
        }
        CommitLogResult pos = log.log(entry, true);
        apply(pos, entry, false);
    } catch (Exception err) {
        throw new StatementExecutionException(err);
    } finally {
        generalLock.readLock().unlock();
    }
    return new TransactionResult(txId, TransactionResult.OutcomeType.COMMIT);
}
Also used : TransactionResult(herddb.model.TransactionResult) Transaction(herddb.model.Transaction) CommitLogResult(herddb.log.CommitLogResult) LogEntry(herddb.log.LogEntry) DumpedLogEntry(herddb.backup.DumpedLogEntry) StatementExecutionException(herddb.model.StatementExecutionException) 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 5 with CommitLogResult

use of herddb.log.CommitLogResult in project herddb by diennea.

the class TableSpaceManager method startAsLeader.

void startAsLeader() throws DataStorageManagerException, DDLException, LogNotAvailableException {
    if (virtual) {
    } else {
        LOGGER.log(Level.SEVERE, "startAsLeader {0} tablespace {1}", new Object[] { nodeId, tableSpaceName });
        recoverForLeadership();
        // every pending transaction MUST be rollback back
        List<Long> pending_transactions = new ArrayList<>(this.transactions.keySet());
        log.startWriting();
        LOGGER.log(Level.SEVERE, "startAsLeader {0} tablespace {1} log, there were {2} pending transactions to be rolledback", new Object[] { nodeId, tableSpaceName, pending_transactions.size() });
        for (long tx : pending_transactions) {
            LOGGER.log(Level.FINER, "rolling back transaction {0}", tx);
            LogEntry rollback = LogEntryFactory.rollbackTransaction(tx);
            // let followers see the rollback on the log
            CommitLogResult pos = log.log(rollback, true);
            apply(pos, rollback, false);
        }
    }
    leader = true;
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) CommitLogResult(herddb.log.CommitLogResult) LogEntry(herddb.log.LogEntry) DumpedLogEntry(herddb.backup.DumpedLogEntry)

Aggregations

CommitLogResult (herddb.log.CommitLogResult)18 LogNotAvailableException (herddb.log.LogNotAvailableException)15 LogEntry (herddb.log.LogEntry)14 StatementExecutionException (herddb.model.StatementExecutionException)13 DataStorageManagerException (herddb.storage.DataStorageManagerException)11 DumpedLogEntry (herddb.backup.DumpedLogEntry)9 IndexAlreadyExistsException (herddb.model.IndexAlreadyExistsException)7 FullRecoveryNeededException (herddb.log.FullRecoveryNeededException)6 IndexDoesNotExistException (herddb.model.IndexDoesNotExistException)6 TableAlreadyExistsException (herddb.model.TableAlreadyExistsException)6 TableDoesNotExistException (herddb.model.TableDoesNotExistException)6 EOFException (java.io.EOFException)6 ClientSideMetadataProviderException (herddb.client.ClientSideMetadataProviderException)5 HDBException (herddb.client.HDBException)5 LogSequenceNumber (herddb.log.LogSequenceNumber)5 MetadataStorageManagerException (herddb.metadata.MetadataStorageManagerException)5 DDLException (herddb.model.DDLException)5 DDLStatementExecutionResult (herddb.model.DDLStatementExecutionResult)5 TimeoutException (java.util.concurrent.TimeoutException)5 DMLStatementExecutionResult (herddb.model.DMLStatementExecutionResult)4