use of herddb.log.LogNotAvailableException in project herddb by diennea.
the class ZookeeperMetadataStorageManager method readActualLedgersListFromZookeeper.
/**
* Let (embedded) brokers read actual list of ledgers used. in order to perform extrernal clean ups
*
* @param zooKeeper
* @param ledgersPath
* @param tableSpaceUUID
* @return
* @throws LogNotAvailableException
*/
public static LedgersInfo readActualLedgersListFromZookeeper(ZooKeeper zooKeeper, String ledgersPath, String tableSpaceUUID) throws LogNotAvailableException {
while (zooKeeper.getState() != ZooKeeper.States.CLOSED) {
try {
Stat stat = new Stat();
byte[] actualLedgers = zooKeeper.getData(ledgersPath + "/" + tableSpaceUUID, false, stat);
return LedgersInfo.deserialize(actualLedgers, stat.getVersion());
} catch (KeeperException.NoNodeException firstboot) {
LOGGER.log(Level.INFO, "node " + ledgersPath + "/" + tableSpaceUUID + " not found");
// -1 is a special ZK version
return LedgersInfo.deserialize(null, -1);
} catch (KeeperException.ConnectionLossException error) {
LOGGER.log(Level.SEVERE, "error while loading actual ledgers list at " + ledgersPath + "/" + tableSpaceUUID, error);
try {
Thread.sleep(1000);
} catch (InterruptedException err) {
// maybe stopping
throw new LogNotAvailableException(err);
}
} catch (Exception error) {
LOGGER.log(Level.SEVERE, "error while loading actual ledgers list at " + ledgersPath + "/" + tableSpaceUUID, error);
throw new LogNotAvailableException(error);
}
}
throw new LogNotAvailableException(new Exception("zk client closed"));
}
use of herddb.log.LogNotAvailableException in project herddb by diennea.
the class BookkeeperCommitLog method log.
@Override
public CommitLogResult log(LogEntry edit, boolean sync) {
CompletableFuture<LogSequenceNumber> res;
CommitFileWriter _writer = null;
try {
_writer = getValidWriter();
} catch (LogNotAvailableException errorWhileRollingLedger) {
LOGGER.log(Level.SEVERE, "Cannot get a valid writer for " + tableSpaceDescription(), errorWhileRollingLedger);
}
if (failed) {
res = FutureUtils.exception(new LogNotAvailableException(new Exception("this commitlog is failed, tablespace " + tableSpaceDescription() + ", node " + this.localNodeId)).fillInStackTrace());
} else if (closed || _writer == null) {
res = FutureUtils.exception(new LogNotAvailableException(new Exception("this commitlog has been closed, tablespace " + tableSpaceDescription() + ", node " + this.localNodeId)).fillInStackTrace());
} else {
res = _writer.writeEntry(edit);
// publish the lastSequenceNumber
// we must return a new CompletableFuture that completes only
// AFTER lastSequenceNumber is updated
// otherwise while doing a checkpoint we could observe
// an old value for lastSequenceNumber
// in case of a slow system
res = res.thenApply((pos) -> {
if (lastLedgerId == pos.ledgerId) {
lastSequenceNumber.accumulateAndGet(pos.offset, EnsureLongIncrementAccumulator.INSTANCE);
}
notifyListeners(pos, edit);
return pos;
});
}
if (!sync) {
// sending a fake completed result
return new CommitLogResult(CompletableFuture.completedFuture(null), true, /*
* deferred
*/
false);
} else {
return new CommitLogResult(res, false, /*
* deferred
*/
true);
}
}
use of herddb.log.LogNotAvailableException in project herddb by diennea.
the class BookkeeperCommitLog method followTheLeader.
@Override
public void followTheLeader(LogSequenceNumber lastPosition, EntryAcceptor consumer, FollowerContext context) throws LogNotAvailableException {
if (LOGGER.isLoggable(Level.FINER)) {
LOGGER.finer(tableSpaceDescription() + " followTheLeader lastPosition:" + lastPosition);
}
BKFollowerContext fContext = (BKFollowerContext) context;
try {
fContext.ensureOpenReader(lastPosition);
if (fContext.currentLedger == null) {
// no data to read
if (LOGGER.isLoggable(Level.FINER)) {
LOGGER.finer(tableSpaceDescription() + " no more data to read for now");
}
return;
}
long nextEntry = fContext.nextEntryToRead;
long lastAddConfirmed = fContext.currentLedger.getLastAddConfirmed();
if (LOGGER.isLoggable(Level.FINER)) {
LOGGER.finer(tableSpaceDescription() + " next entry to read " + nextEntry + " from ledger " + fContext.currentLedger.getId() + " lastAddConfiremd " + lastAddConfirmed);
}
if (lastAddConfirmed < nextEntry) {
if (LOGGER.isLoggable(Level.FINER)) {
LOGGER.finer(tableSpaceDescription() + " ledger not closed but there is nothing to read by now");
}
return;
}
ReadHandle lh = fContext.currentLedger;
try (LastConfirmedAndEntry entryAndLac = lh.readLastAddConfirmedAndEntry(nextEntry, LONG_POLL_TIMEOUT, false)) {
if (entryAndLac.hasEntry()) {
org.apache.bookkeeper.client.api.LedgerEntry e = entryAndLac.getEntry();
boolean canContinue = acceptEntryForFollower(e, consumer);
if (!canContinue) {
LOGGER.log(Level.INFO, "exit follower {0}", tableSpaceDescription());
return;
}
long startEntry = nextEntry + 1;
long endEntry = entryAndLac.getLastAddConfirmed();
if (startEntry > endEntry) {
return;
}
// to be read then read them
if (endEntry - startEntry > MAX_ENTRY_TO_TAIL) {
// put a bound on the max entries to read per round
endEntry = startEntry + MAX_ENTRY_TO_TAIL;
}
try (LedgerEntries entries = lh.read(startEntry, endEntry)) {
for (org.apache.bookkeeper.client.api.LedgerEntry ee : entries) {
acceptEntryForFollower(ee, consumer);
}
}
}
}
} catch (BKClientClosedException err) {
LOGGER.log(Level.FINE, "stop following " + tableSpaceDescription(), err);
} catch (org.apache.bookkeeper.client.api.BKException err) {
LOGGER.log(Level.SEVERE, tableSpaceDescription() + " internal BK error", err);
throw new LogNotAvailableException(err);
} catch (InterruptedException err) {
LOGGER.log(Level.SEVERE, tableSpaceDescription() + " interrupted", err);
Thread.currentThread().interrupt();
throw new LogNotAvailableException(err);
} catch (LogNotAvailableException err) {
LOGGER.log(Level.SEVERE, tableSpaceDescription() + " internal error", err);
throw err;
} catch (Exception err) {
LOGGER.log(Level.SEVERE, tableSpaceDescription() + " internal error", err);
throw new LogNotAvailableException(err);
}
}
use of herddb.log.LogNotAvailableException in project herddb by diennea.
the class TableSpaceManager method dropTable.
private StatementExecutionResult dropTable(DropTableStatement statement, Transaction transaction) throws StatementExecutionException {
generalLock.writeLock().lock();
try {
if (!tables.containsKey(statement.getTable())) {
if (statement.isIfExists()) {
return new DDLStatementExecutionResult(transaction != null ? transaction.transactionId : 0);
}
throw new TableDoesNotExistException("table does not exist " + statement.getTable() + " on tableSpace " + statement.getTableSpace());
}
if (transaction != null && transaction.isTableDropped(statement.getTable())) {
if (statement.isIfExists()) {
return new DDLStatementExecutionResult(transaction.transactionId);
}
throw new TableDoesNotExistException("table does not exist " + statement.getTable() + " on tableSpace " + statement.getTableSpace());
}
Map<String, AbstractIndexManager> indexesOnTable = indexesByTable.get(statement.getTable());
if (indexesOnTable != null) {
for (String index : indexesOnTable.keySet()) {
LogEntry entry = LogEntryFactory.dropIndex(index, transaction);
CommitLogResult pos = log.log(entry, entry.transactionId <= 0);
apply(pos, entry, false);
}
}
LogEntry entry = LogEntryFactory.dropTable(statement.getTable(), transaction);
CommitLogResult pos = log.log(entry, entry.transactionId <= 0);
apply(pos, entry, false);
return new DDLStatementExecutionResult(entry.transactionId);
} catch (DataStorageManagerException | LogNotAvailableException err) {
throw new StatementExecutionException(err);
} finally {
generalLock.writeLock().unlock();
}
}
use of herddb.log.LogNotAvailableException in project herddb by diennea.
the class TableSpaceManager method createTable.
private StatementExecutionResult createTable(CreateTableStatement statement, Transaction transaction) throws StatementExecutionException {
generalLock.writeLock().lock();
try {
if (tables.containsKey(statement.getTableDefinition().name)) {
throw new TableAlreadyExistsException(statement.getTableDefinition().name);
}
for (Index additionalIndex : statement.getAdditionalIndexes()) {
if (indexes.containsKey(additionalIndex.name)) {
throw new IndexAlreadyExistsException(additionalIndex.name);
}
}
LogEntry entry = LogEntryFactory.createTable(statement.getTableDefinition(), transaction);
CommitLogResult pos = log.log(entry, entry.transactionId <= 0);
apply(pos, entry, false);
for (Index additionalIndex : statement.getAdditionalIndexes()) {
LogEntry index_entry = LogEntryFactory.createIndex(additionalIndex, transaction);
CommitLogResult index_pos = log.log(index_entry, index_entry.transactionId <= 0);
apply(index_pos, index_entry, false);
}
return new DDLStatementExecutionResult(entry.transactionId);
} catch (DataStorageManagerException | LogNotAvailableException err) {
throw new StatementExecutionException(err);
} finally {
generalLock.writeLock().unlock();
}
}
Aggregations