Search in sources :

Example 6 with LogEntry

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

use of herddb.log.LogEntry 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 8 with LogEntry

use of herddb.log.LogEntry 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)

Example 9 with LogEntry

use of herddb.log.LogEntry 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)

Example 10 with LogEntry

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

the class TableSpaceManager method rollbackTransaction.

private StatementExecutionResult rollbackTransaction(RollbackTransactionStatement rollbackTransactionStatement) throws StatementExecutionException {
    long txId = rollbackTransactionStatement.getTransactionId();
    LogEntry entry = LogEntryFactory.rollbackTransaction(txId);
    generalLock.readLock().lock();
    try {
        Transaction tx = transactions.get(txId);
        if (tx == null) {
            throw new StatementExecutionException("no such transaction " + rollbackTransactionStatement.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.ROLLBACK);
}
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)

Aggregations

LogEntry (herddb.log.LogEntry)22 CommitLogResult (herddb.log.CommitLogResult)14 LogNotAvailableException (herddb.log.LogNotAvailableException)14 StatementExecutionException (herddb.model.StatementExecutionException)12 DataStorageManagerException (herddb.storage.DataStorageManagerException)11 DumpedLogEntry (herddb.backup.DumpedLogEntry)10 LogSequenceNumber (herddb.log.LogSequenceNumber)9 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)7 CommitLog (herddb.log.CommitLog)6 IndexAlreadyExistsException (herddb.model.IndexAlreadyExistsException)6 EOFException (java.io.EOFException)6 FullRecoveryNeededException (herddb.log.FullRecoveryNeededException)5 DDLStatementExecutionResult (herddb.model.DDLStatementExecutionResult)5 IndexDoesNotExistException (herddb.model.IndexDoesNotExistException)5 TableAlreadyExistsException (herddb.model.TableAlreadyExistsException)5 TableDoesNotExistException (herddb.model.TableDoesNotExistException)5 TimeoutException (java.util.concurrent.TimeoutException)5 Test (org.junit.Test)5 ClientSideMetadataProviderException (herddb.client.ClientSideMetadataProviderException)4 HDBException (herddb.client.HDBException)4