Search in sources :

Example 16 with LogNotAvailableException

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"));
}
Also used : Stat(org.apache.zookeeper.data.Stat) KeeperException(org.apache.zookeeper.KeeperException) MetadataStorageManagerException(herddb.metadata.MetadataStorageManagerException) TableSpaceDoesNotExistException(herddb.model.TableSpaceDoesNotExistException) LogNotAvailableException(herddb.log.LogNotAvailableException) KeeperException(org.apache.zookeeper.KeeperException) DDLException(herddb.model.DDLException) IOException(java.io.IOException) TableSpaceAlreadyExistsException(herddb.model.TableSpaceAlreadyExistsException) LogNotAvailableException(herddb.log.LogNotAvailableException)

Example 17 with LogNotAvailableException

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);
    }
}
Also used : LogSequenceNumber(herddb.log.LogSequenceNumber) CommitLogResult(herddb.log.CommitLogResult) BKNotEnoughBookiesException(org.apache.bookkeeper.client.BKException.BKNotEnoughBookiesException) LogNotAvailableException(herddb.log.LogNotAvailableException) IOException(java.io.IOException) CompletionException(java.util.concurrent.CompletionException) BKException(org.apache.bookkeeper.client.BKException) FullRecoveryNeededException(herddb.log.FullRecoveryNeededException) BKClientClosedException(org.apache.bookkeeper.client.BKException.BKClientClosedException) LogNotAvailableException(herddb.log.LogNotAvailableException)

Example 18 with LogNotAvailableException

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);
    }
}
Also used : LastConfirmedAndEntry(org.apache.bookkeeper.client.api.LastConfirmedAndEntry) BKNotEnoughBookiesException(org.apache.bookkeeper.client.BKException.BKNotEnoughBookiesException) LogNotAvailableException(herddb.log.LogNotAvailableException) IOException(java.io.IOException) CompletionException(java.util.concurrent.CompletionException) BKException(org.apache.bookkeeper.client.BKException) FullRecoveryNeededException(herddb.log.FullRecoveryNeededException) BKClientClosedException(org.apache.bookkeeper.client.BKException.BKClientClosedException) ReadHandle(org.apache.bookkeeper.client.api.ReadHandle) LedgerEntries(org.apache.bookkeeper.client.api.LedgerEntries) BKClientClosedException(org.apache.bookkeeper.client.BKException.BKClientClosedException) LogNotAvailableException(herddb.log.LogNotAvailableException)

Example 19 with LogNotAvailableException

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();
    }
}
Also used : TableDoesNotExistException(herddb.model.TableDoesNotExistException) DataStorageManagerException(herddb.storage.DataStorageManagerException) 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 20 with LogNotAvailableException

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();
    }
}
Also used : TableAlreadyExistsException(herddb.model.TableAlreadyExistsException) DataStorageManagerException(herddb.storage.DataStorageManagerException) IndexAlreadyExistsException(herddb.model.IndexAlreadyExistsException) Index(herddb.model.Index) 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

LogNotAvailableException (herddb.log.LogNotAvailableException)35 CommitLogResult (herddb.log.CommitLogResult)20 LogEntry (herddb.log.LogEntry)19 StatementExecutionException (herddb.model.StatementExecutionException)18 DataStorageManagerException (herddb.storage.DataStorageManagerException)18 IOException (java.io.IOException)15 LogSequenceNumber (herddb.log.LogSequenceNumber)12 DDLStatementExecutionResult (herddb.model.DDLStatementExecutionResult)11 DumpedLogEntry (herddb.backup.DumpedLogEntry)10 DDLException (herddb.model.DDLException)9 ArrayList (java.util.ArrayList)9 MetadataStorageManagerException (herddb.metadata.MetadataStorageManagerException)7 DMLStatementExecutionResult (herddb.model.DMLStatementExecutionResult)7 IndexAlreadyExistsException (herddb.model.IndexAlreadyExistsException)7 Table (herddb.model.Table)7 ScanStatement (herddb.model.commands.ScanStatement)7 Bytes (herddb.utils.Bytes)7 AtomicLong (java.util.concurrent.atomic.AtomicLong)7 CommitLog (herddb.log.CommitLog)6 FullRecoveryNeededException (herddb.log.FullRecoveryNeededException)6