Search in sources :

Example 1 with MetadataNotFoundException

use of org.apache.bookkeeper.mledger.ManagedLedgerException.MetadataNotFoundException in project pulsar by yahoo.

the class ReadOnlyManagedLedgerImpl method initializeAndCreateCursor.

CompletableFuture<ReadOnlyCursor> initializeAndCreateCursor(PositionImpl startPosition) {
    CompletableFuture<ReadOnlyCursor> future = new CompletableFuture<>();
    // Fetch the list of existing ledgers in the managed ledger
    store.getManagedLedgerInfo(name, false, new MetaStoreCallback<ManagedLedgerInfo>() {

        @Override
        public void operationComplete(ManagedLedgerInfo mlInfo, Stat stat) {
            state = State.LedgerOpened;
            for (LedgerInfo ls : mlInfo.getLedgerInfoList()) {
                ledgers.put(ls.getLedgerId(), ls);
            }
            // Last ledger stat may be zeroed, we must update it
            if (ledgers.size() > 0 && ledgers.lastEntry().getValue().getEntries() == 0) {
                long lastLedgerId = ledgers.lastKey();
                // Fetch last add confirmed for last ledger
                bookKeeper.newOpenLedgerOp().withRecovery(false).withLedgerId(lastLedgerId).withDigestType(config.getDigestType()).withPassword(config.getPassword()).execute().thenAccept(readHandle -> {
                    readHandle.readLastAddConfirmedAsync().thenAccept(lastAddConfirmed -> {
                        LedgerInfo info = LedgerInfo.newBuilder().setLedgerId(lastLedgerId).setEntries(lastAddConfirmed + 1).setSize(readHandle.getLength()).setTimestamp(clock.millis()).build();
                        ledgers.put(lastLedgerId, info);
                        future.complete(createReadOnlyCursor(startPosition));
                    }).exceptionally(ex -> {
                        if (ex instanceof CompletionException && ex.getCause() instanceof IllegalArgumentException) {
                            // The last ledger was empty, so we cannot read the last add confirmed.
                            LedgerInfo info = LedgerInfo.newBuilder().setLedgerId(lastLedgerId).setEntries(0).setSize(0).setTimestamp(clock.millis()).build();
                            ledgers.put(lastLedgerId, info);
                            future.complete(createReadOnlyCursor(startPosition));
                        } else {
                            future.completeExceptionally(new ManagedLedgerException(ex));
                        }
                        return null;
                    });
                }).exceptionally(ex -> {
                    if (ex instanceof CompletionException && ex.getCause() instanceof ArrayIndexOutOfBoundsException) {
                        // The last ledger was empty, so we cannot read the last add confirmed.
                        LedgerInfo info = LedgerInfo.newBuilder().setLedgerId(lastLedgerId).setEntries(0).setSize(0).setTimestamp(clock.millis()).build();
                        ledgers.put(lastLedgerId, info);
                        future.complete(createReadOnlyCursor(startPosition));
                    } else {
                        future.completeExceptionally(new ManagedLedgerException(ex));
                    }
                    return null;
                });
            } else {
                // The read-only managed ledger is ready to use
                future.complete(createReadOnlyCursor(startPosition));
            }
        }

        @Override
        public void operationFailed(MetaStoreException e) {
            if (e instanceof MetadataNotFoundException) {
                future.completeExceptionally(new ManagedLedgerNotFoundException(e));
            } else {
                future.completeExceptionally(new ManagedLedgerException(e));
            }
        }
    });
    return future;
}
Also used : ManagedLedgerInfo(org.apache.bookkeeper.mledger.proto.MLDataFormats.ManagedLedgerInfo) ManagedLedgerNotFoundException(org.apache.bookkeeper.mledger.ManagedLedgerException.ManagedLedgerNotFoundException) Stat(org.apache.pulsar.metadata.api.Stat) ReadOnlyCursor(org.apache.bookkeeper.mledger.ReadOnlyCursor) LedgerInfo(org.apache.bookkeeper.mledger.proto.MLDataFormats.ManagedLedgerInfo.LedgerInfo) OrderedScheduler(org.apache.bookkeeper.common.util.OrderedScheduler) Range(com.google.common.collect.Range) CompletableFuture(java.util.concurrent.CompletableFuture) CompletionException(java.util.concurrent.CompletionException) MetaStoreCallback(org.apache.bookkeeper.mledger.impl.MetaStore.MetaStoreCallback) BookKeeper(org.apache.bookkeeper.client.BookKeeper) ManagedLedgerException(org.apache.bookkeeper.mledger.ManagedLedgerException) MetadataNotFoundException(org.apache.bookkeeper.mledger.ManagedLedgerException.MetadataNotFoundException) Slf4j(lombok.extern.slf4j.Slf4j) MetaStoreException(org.apache.bookkeeper.mledger.ManagedLedgerException.MetaStoreException) ManagedLedgerConfig(org.apache.bookkeeper.mledger.ManagedLedgerConfig) AsyncCallbacks(org.apache.bookkeeper.mledger.AsyncCallbacks) ReadOnlyCursor(org.apache.bookkeeper.mledger.ReadOnlyCursor) ManagedLedgerInfo(org.apache.bookkeeper.mledger.proto.MLDataFormats.ManagedLedgerInfo) ManagedLedgerInfo(org.apache.bookkeeper.mledger.proto.MLDataFormats.ManagedLedgerInfo) LedgerInfo(org.apache.bookkeeper.mledger.proto.MLDataFormats.ManagedLedgerInfo.LedgerInfo) MetaStoreException(org.apache.bookkeeper.mledger.ManagedLedgerException.MetaStoreException) MetadataNotFoundException(org.apache.bookkeeper.mledger.ManagedLedgerException.MetadataNotFoundException) CompletableFuture(java.util.concurrent.CompletableFuture) ManagedLedgerException(org.apache.bookkeeper.mledger.ManagedLedgerException) ManagedLedgerNotFoundException(org.apache.bookkeeper.mledger.ManagedLedgerException.ManagedLedgerNotFoundException) Stat(org.apache.pulsar.metadata.api.Stat) CompletionException(java.util.concurrent.CompletionException)

Example 2 with MetadataNotFoundException

use of org.apache.bookkeeper.mledger.ManagedLedgerException.MetadataNotFoundException in project incubator-pulsar by apache.

the class ReadOnlyManagedLedgerImpl method initializeAndCreateCursor.

CompletableFuture<ReadOnlyCursor> initializeAndCreateCursor(PositionImpl startPosition) {
    CompletableFuture<ReadOnlyCursor> future = new CompletableFuture<>();
    // Fetch the list of existing ledgers in the managed ledger
    store.getManagedLedgerInfo(name, false, new MetaStoreCallback<ManagedLedgerInfo>() {

        @Override
        public void operationComplete(ManagedLedgerInfo mlInfo, Stat stat) {
            state = State.LedgerOpened;
            for (LedgerInfo ls : mlInfo.getLedgerInfoList()) {
                ledgers.put(ls.getLedgerId(), ls);
            }
            // Last ledger stat may be zeroed, we must update it
            if (ledgers.size() > 0 && ledgers.lastEntry().getValue().getEntries() == 0) {
                long lastLedgerId = ledgers.lastKey();
                // Fetch last add confirmed for last ledger
                bookKeeper.newOpenLedgerOp().withRecovery(false).withLedgerId(lastLedgerId).withDigestType(config.getDigestType()).withPassword(config.getPassword()).execute().thenAccept(readHandle -> {
                    readHandle.readLastAddConfirmedAsync().thenAccept(lastAddConfirmed -> {
                        LedgerInfo info = LedgerInfo.newBuilder().setLedgerId(lastLedgerId).setEntries(lastAddConfirmed + 1).setSize(readHandle.getLength()).setTimestamp(clock.millis()).build();
                        ledgers.put(lastLedgerId, info);
                        future.complete(createReadOnlyCursor(startPosition));
                    }).exceptionally(ex -> {
                        if (ex instanceof CompletionException && ex.getCause() instanceof IllegalArgumentException) {
                            // The last ledger was empty, so we cannot read the last add confirmed.
                            LedgerInfo info = LedgerInfo.newBuilder().setLedgerId(lastLedgerId).setEntries(0).setSize(0).setTimestamp(clock.millis()).build();
                            ledgers.put(lastLedgerId, info);
                            future.complete(createReadOnlyCursor(startPosition));
                        } else {
                            future.completeExceptionally(new ManagedLedgerException(ex));
                        }
                        return null;
                    });
                }).exceptionally(ex -> {
                    if (ex instanceof CompletionException && ex.getCause() instanceof ArrayIndexOutOfBoundsException) {
                        // The last ledger was empty, so we cannot read the last add confirmed.
                        LedgerInfo info = LedgerInfo.newBuilder().setLedgerId(lastLedgerId).setEntries(0).setSize(0).setTimestamp(clock.millis()).build();
                        ledgers.put(lastLedgerId, info);
                        future.complete(createReadOnlyCursor(startPosition));
                    } else {
                        future.completeExceptionally(new ManagedLedgerException(ex));
                    }
                    return null;
                });
            } else {
                // The read-only managed ledger is ready to use
                future.complete(createReadOnlyCursor(startPosition));
            }
        }

        @Override
        public void operationFailed(MetaStoreException e) {
            if (e instanceof MetadataNotFoundException) {
                future.completeExceptionally(new ManagedLedgerNotFoundException(e));
            } else {
                future.completeExceptionally(new ManagedLedgerException(e));
            }
        }
    });
    return future;
}
Also used : ManagedLedgerInfo(org.apache.bookkeeper.mledger.proto.MLDataFormats.ManagedLedgerInfo) ManagedLedgerNotFoundException(org.apache.bookkeeper.mledger.ManagedLedgerException.ManagedLedgerNotFoundException) Stat(org.apache.pulsar.metadata.api.Stat) ReadOnlyCursor(org.apache.bookkeeper.mledger.ReadOnlyCursor) LedgerInfo(org.apache.bookkeeper.mledger.proto.MLDataFormats.ManagedLedgerInfo.LedgerInfo) OrderedScheduler(org.apache.bookkeeper.common.util.OrderedScheduler) Range(com.google.common.collect.Range) CompletableFuture(java.util.concurrent.CompletableFuture) CompletionException(java.util.concurrent.CompletionException) MetaStoreCallback(org.apache.bookkeeper.mledger.impl.MetaStore.MetaStoreCallback) BookKeeper(org.apache.bookkeeper.client.BookKeeper) ManagedLedgerException(org.apache.bookkeeper.mledger.ManagedLedgerException) MetadataNotFoundException(org.apache.bookkeeper.mledger.ManagedLedgerException.MetadataNotFoundException) Slf4j(lombok.extern.slf4j.Slf4j) MetaStoreException(org.apache.bookkeeper.mledger.ManagedLedgerException.MetaStoreException) ManagedLedgerConfig(org.apache.bookkeeper.mledger.ManagedLedgerConfig) AsyncCallbacks(org.apache.bookkeeper.mledger.AsyncCallbacks) ReadOnlyCursor(org.apache.bookkeeper.mledger.ReadOnlyCursor) ManagedLedgerInfo(org.apache.bookkeeper.mledger.proto.MLDataFormats.ManagedLedgerInfo) ManagedLedgerInfo(org.apache.bookkeeper.mledger.proto.MLDataFormats.ManagedLedgerInfo) LedgerInfo(org.apache.bookkeeper.mledger.proto.MLDataFormats.ManagedLedgerInfo.LedgerInfo) MetaStoreException(org.apache.bookkeeper.mledger.ManagedLedgerException.MetaStoreException) MetadataNotFoundException(org.apache.bookkeeper.mledger.ManagedLedgerException.MetadataNotFoundException) CompletableFuture(java.util.concurrent.CompletableFuture) ManagedLedgerException(org.apache.bookkeeper.mledger.ManagedLedgerException) ManagedLedgerNotFoundException(org.apache.bookkeeper.mledger.ManagedLedgerException.ManagedLedgerNotFoundException) Stat(org.apache.pulsar.metadata.api.Stat) CompletionException(java.util.concurrent.CompletionException)

Example 3 with MetadataNotFoundException

use of org.apache.bookkeeper.mledger.ManagedLedgerException.MetadataNotFoundException in project pulsar by apache.

the class ReadOnlyManagedLedgerImpl method initializeAndCreateCursor.

CompletableFuture<ReadOnlyCursor> initializeAndCreateCursor(PositionImpl startPosition) {
    CompletableFuture<ReadOnlyCursor> future = new CompletableFuture<>();
    // Fetch the list of existing ledgers in the managed ledger
    store.getManagedLedgerInfo(name, false, new MetaStoreCallback<ManagedLedgerInfo>() {

        @Override
        public void operationComplete(ManagedLedgerInfo mlInfo, Stat stat) {
            state = State.LedgerOpened;
            for (LedgerInfo ls : mlInfo.getLedgerInfoList()) {
                ledgers.put(ls.getLedgerId(), ls);
            }
            // Last ledger stat may be zeroed, we must update it
            if (ledgers.size() > 0 && ledgers.lastEntry().getValue().getEntries() == 0) {
                long lastLedgerId = ledgers.lastKey();
                // Fetch last add confirmed for last ledger
                bookKeeper.newOpenLedgerOp().withRecovery(false).withLedgerId(lastLedgerId).withDigestType(config.getDigestType()).withPassword(config.getPassword()).execute().thenAccept(readHandle -> {
                    readHandle.readLastAddConfirmedAsync().thenAccept(lastAddConfirmed -> {
                        LedgerInfo info = LedgerInfo.newBuilder().setLedgerId(lastLedgerId).setEntries(lastAddConfirmed + 1).setSize(readHandle.getLength()).setTimestamp(clock.millis()).build();
                        ledgers.put(lastLedgerId, info);
                        future.complete(createReadOnlyCursor(startPosition));
                    }).exceptionally(ex -> {
                        if (ex instanceof CompletionException && ex.getCause() instanceof IllegalArgumentException) {
                            // The last ledger was empty, so we cannot read the last add confirmed.
                            LedgerInfo info = LedgerInfo.newBuilder().setLedgerId(lastLedgerId).setEntries(0).setSize(0).setTimestamp(clock.millis()).build();
                            ledgers.put(lastLedgerId, info);
                            future.complete(createReadOnlyCursor(startPosition));
                        } else {
                            future.completeExceptionally(new ManagedLedgerException(ex));
                        }
                        return null;
                    });
                }).exceptionally(ex -> {
                    if (ex instanceof CompletionException && ex.getCause() instanceof ArrayIndexOutOfBoundsException) {
                        // The last ledger was empty, so we cannot read the last add confirmed.
                        LedgerInfo info = LedgerInfo.newBuilder().setLedgerId(lastLedgerId).setEntries(0).setSize(0).setTimestamp(clock.millis()).build();
                        ledgers.put(lastLedgerId, info);
                        future.complete(createReadOnlyCursor(startPosition));
                    } else {
                        future.completeExceptionally(new ManagedLedgerException(ex));
                    }
                    return null;
                });
            } else {
                // The read-only managed ledger is ready to use
                future.complete(createReadOnlyCursor(startPosition));
            }
        }

        @Override
        public void operationFailed(MetaStoreException e) {
            if (e instanceof MetadataNotFoundException) {
                future.completeExceptionally(new ManagedLedgerNotFoundException(e));
            } else {
                future.completeExceptionally(new ManagedLedgerException(e));
            }
        }
    });
    return future;
}
Also used : ManagedLedgerInfo(org.apache.bookkeeper.mledger.proto.MLDataFormats.ManagedLedgerInfo) ManagedLedgerNotFoundException(org.apache.bookkeeper.mledger.ManagedLedgerException.ManagedLedgerNotFoundException) Stat(org.apache.pulsar.metadata.api.Stat) ReadOnlyCursor(org.apache.bookkeeper.mledger.ReadOnlyCursor) LedgerInfo(org.apache.bookkeeper.mledger.proto.MLDataFormats.ManagedLedgerInfo.LedgerInfo) OrderedScheduler(org.apache.bookkeeper.common.util.OrderedScheduler) Range(com.google.common.collect.Range) CompletableFuture(java.util.concurrent.CompletableFuture) CompletionException(java.util.concurrent.CompletionException) MetaStoreCallback(org.apache.bookkeeper.mledger.impl.MetaStore.MetaStoreCallback) BookKeeper(org.apache.bookkeeper.client.BookKeeper) ManagedLedgerException(org.apache.bookkeeper.mledger.ManagedLedgerException) MetadataNotFoundException(org.apache.bookkeeper.mledger.ManagedLedgerException.MetadataNotFoundException) Slf4j(lombok.extern.slf4j.Slf4j) MetaStoreException(org.apache.bookkeeper.mledger.ManagedLedgerException.MetaStoreException) ManagedLedgerConfig(org.apache.bookkeeper.mledger.ManagedLedgerConfig) AsyncCallbacks(org.apache.bookkeeper.mledger.AsyncCallbacks) ReadOnlyCursor(org.apache.bookkeeper.mledger.ReadOnlyCursor) ManagedLedgerInfo(org.apache.bookkeeper.mledger.proto.MLDataFormats.ManagedLedgerInfo) ManagedLedgerInfo(org.apache.bookkeeper.mledger.proto.MLDataFormats.ManagedLedgerInfo) LedgerInfo(org.apache.bookkeeper.mledger.proto.MLDataFormats.ManagedLedgerInfo.LedgerInfo) MetaStoreException(org.apache.bookkeeper.mledger.ManagedLedgerException.MetaStoreException) MetadataNotFoundException(org.apache.bookkeeper.mledger.ManagedLedgerException.MetadataNotFoundException) CompletableFuture(java.util.concurrent.CompletableFuture) ManagedLedgerException(org.apache.bookkeeper.mledger.ManagedLedgerException) ManagedLedgerNotFoundException(org.apache.bookkeeper.mledger.ManagedLedgerException.ManagedLedgerNotFoundException) Stat(org.apache.pulsar.metadata.api.Stat) CompletionException(java.util.concurrent.CompletionException)

Aggregations

Range (com.google.common.collect.Range)3 CompletableFuture (java.util.concurrent.CompletableFuture)3 CompletionException (java.util.concurrent.CompletionException)3 Slf4j (lombok.extern.slf4j.Slf4j)3 BookKeeper (org.apache.bookkeeper.client.BookKeeper)3 OrderedScheduler (org.apache.bookkeeper.common.util.OrderedScheduler)3 AsyncCallbacks (org.apache.bookkeeper.mledger.AsyncCallbacks)3 ManagedLedgerConfig (org.apache.bookkeeper.mledger.ManagedLedgerConfig)3 ManagedLedgerException (org.apache.bookkeeper.mledger.ManagedLedgerException)3 ManagedLedgerNotFoundException (org.apache.bookkeeper.mledger.ManagedLedgerException.ManagedLedgerNotFoundException)3 MetaStoreException (org.apache.bookkeeper.mledger.ManagedLedgerException.MetaStoreException)3 MetadataNotFoundException (org.apache.bookkeeper.mledger.ManagedLedgerException.MetadataNotFoundException)3 ReadOnlyCursor (org.apache.bookkeeper.mledger.ReadOnlyCursor)3 MetaStoreCallback (org.apache.bookkeeper.mledger.impl.MetaStore.MetaStoreCallback)3 ManagedLedgerInfo (org.apache.bookkeeper.mledger.proto.MLDataFormats.ManagedLedgerInfo)3 LedgerInfo (org.apache.bookkeeper.mledger.proto.MLDataFormats.ManagedLedgerInfo.LedgerInfo)3 Stat (org.apache.pulsar.metadata.api.Stat)3