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();
}
}
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);
}
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;
}
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();
}
}
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);
}
Aggregations