Package org.apache.hedwig.protocol.PubSubProtocol

Examples of org.apache.hedwig.protocol.PubSubProtocol.LedgerRange


         * Process old version ledger ranges to fetch start seq id.
         */
        void getStartSeqIdToProcessTopicLedgerRanges(
            final List<LedgerRange> rangesList, final Version version) {

            final LedgerRange range = rangesList.get(0);

            if (!range.hasEndSeqIdIncluded()) {
                // process topic ledger ranges directly
                processTopicLedgerRanges(rangesList, version, START_SEQ_ID);
                return;
            }

            final long ledgerId = range.getLedgerId();
            // open the first ledger to compute right start seq id
            bk.asyncOpenLedger(ledgerId, DigestType.CRC32, passwd,
            new SafeAsynBKCallback.OpenCallback() {

                @Override
                public void safeOpenComplete(int rc, LedgerHandle ledgerHandle, Object ctx) {

                    if (rc == BKException.Code.NoSuchLedgerExistsException) {
                        // process next ledger
                        processTopicLedgerRanges(rangesList, version, START_SEQ_ID);
                        return;
                    } else if (rc != BKException.Code.OK) {
                        BKException bke = BKException.create(rc);
                        logger.error("Could not open ledger {} to get start seq id while acquiring topic {} : {}",
                                     va(ledgerId, topic.toStringUtf8(), bke));
                        cb.operationFailed(ctx, new PubSubException.ServiceDownException(bke));
                        return;
                    }

                    final long numEntriesInLastLedger = ledgerHandle.getLastAddConfirmed() + 1;

                    // the ledger is closed before, calling close is just a nop operation.
                    try {
                        ledgerHandle.close();
                    } catch (InterruptedException ie) {
                        // the exception would never be thrown for a read only ledger handle.
                    } catch (BKException bke) {
                        // the exception would never be thrown for a read only ledger handle.
                    }

                    if (numEntriesInLastLedger <= 0) {
                        String msg = "No entries found in a have-end-seq-id ledger " + ledgerId
                                     + " when acquiring topic " + topic.toStringUtf8() + ".";
                        logger.error(msg);
                        cb.operationFailed(ctx, new PubSubException.UnexpectedConditionException(msg));
                        return;
                    }
                    long endOfLedger = range.getEndSeqIdIncluded().getLocalComponent();
                    long startOfLedger = endOfLedger - numEntriesInLastLedger + 1;

                    processTopicLedgerRanges(rangesList, version, startOfLedger);
                }

View Full Code Here


            Iterator<LedgerRange> lrIterator = rangesList.iterator();

            TopicInfo topicInfo = new TopicInfo();
            while (lrIterator.hasNext()) {
                LedgerRange range = lrIterator.next();

                if (range.hasEndSeqIdIncluded()) {
                    // this means it was a valid and completely closed ledger
                    long endOfLedger = range.getEndSeqIdIncluded().getLocalComponent();
                    if (range.hasStartSeqIdIncluded()) {
                        startOfLedger = range.getStartSeqIdIncluded();
                    } else {
                        range = buildLedgerRange(range.getLedgerId(), startOfLedger,
                                                 range.getEndSeqIdIncluded());
                    }
                    topicInfo.ledgerRanges.put(endOfLedger, new InMemoryLedgerRange(range));
                    if (startOfLedger < endOfLedger + 1) {
                        startOfLedger = endOfLedger + 1;
                    }
                    continue;
                }

                // If it doesn't have a valid end, it must be the last ledger
                if (lrIterator.hasNext()) {
                    String msg = "Ledger-id: " + range.getLedgerId() + " for topic: " + topic.toStringUtf8()
                                 + " is not the last one but still does not have an end seq-id";
                    logger.error(msg);
                    cb.operationFailed(ctx, new PubSubException.UnexpectedConditionException(msg));
                    return;
                }

                if (range.hasStartSeqIdIncluded()) {
                    startOfLedger = range.getStartSeqIdIncluded();
                }

                // The last ledger does not have a valid seq-id, lets try to
                // find it out
                recoverLastTopicLedgerAndOpenNewOne(range.getLedgerId(), startOfLedger,
                                                    version, topicInfo);
                return;
            }

            // All ledgers were found properly closed, just start a new one
View Full Code Here

                                             + " to be " + expectedStartSeqId + " but it was "
                                             + startOfLedger + ".";
                                logger.warn(msg);
                            }

                            LedgerRange lr = buildLedgerRange(ledgerId, startOfLedger, lastMessage.getMsgId());
                            topicInfo.ledgerRanges.put(endOfLedger,
                                    new InMemoryLedgerRange(lr, lh));

                            logger.info("Recovered unclosed ledger: {} for topic: {} with {} entries starting from seq id {}",
                                        va(ledgerId, topic.toStringUtf8(), numEntriesInLastLedger, startOfLedger));
View Full Code Here

                        cb.operationFailed(ctx, new PubSubException.ServiceDownException(bke));
                        return;
                    }
                    long endSeqId = topicInfo.lastSeqIdPushed.getLocalComponent();
                    // update last range
                    LedgerRange lastRange =
                        buildLedgerRange(ledgerId, topicInfo.currentLedgerRange.getStartSeqIdIncluded(),
                                         topicInfo.lastSeqIdPushed);

                    topicInfo.currentLedgerRange.range = lastRange;
                    // put current ledger to ledger ranges
View Full Code Here

        List<LedgerRange> lrs = ranges.getRangesList();
        if (lrs.isEmpty()) {
            return lrs;
        }
        // try to check last ledger (it may still open)
        LedgerRange lastRange = lrs.get(lrs.size() - 1);
        if (lastRange.hasEndSeqIdIncluded()) {
            return lrs;
        }
        // read last confirmed of the opened ledger
        try {
            List<LedgerRange> newLrs = new ArrayList<LedgerRange>();
            newLrs.addAll(lrs);
            lrs = newLrs;
            MessageSeqId lastSeqId;
            if (lrs.size() == 1) {
                lastSeqId = MessageSeqId.newBuilder().setLocalComponent(1).build();
            } else {
                lastSeqId = lrs.get(lrs.size() - 2).getEndSeqIdIncluded();
            }
            LedgerRange newLastRange = refreshLastLedgerRange(lastSeqId, lastRange);
            lrs.set(lrs.size() - 1, newLastRange);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return lrs;
View Full Code Here

            TopicInfo topicInfo = new TopicInfo();

            long startOfLedger = 1;

            while (lrIterator.hasNext()) {
                LedgerRange range = lrIterator.next();

                if (range.hasEndSeqIdIncluded()) {
                    // this means it was a valid and completely closed ledger
                    long endOfLedger = range.getEndSeqIdIncluded().getLocalComponent();
                    topicInfo.ledgerRanges.put(endOfLedger, new InMemoryLedgerRange(range, startOfLedger));
                    startOfLedger = endOfLedger + 1;
                    continue;
                }

                // If it doesn't have a valid end, it must be the last ledger
                if (lrIterator.hasNext()) {
                    String msg = "Ledger-id: " + range.getLedgerId() + " for topic: " + topic.toStringUtf8()
                                 + " is not the last one but still does not have an end seq-id";
                    logger.error(msg);
                    cb.operationFailed(ctx, new PubSubException.UnexpectedConditionException(msg));
                    return;
                }

                // The last ledger does not have a valid seq-id, lets try to
                // find it out
                recoverLastTopicLedgerAndOpenNewOne(range.getLedgerId(), version, topicInfo);
                return;
            }

            // All ledgers were found properly closed, just start a new one
            openNewTopicLedger(version, topicInfo);
View Full Code Here

                                return;
                            }

                            long prevLedgerEnd = topicInfo.ledgerRanges.isEmpty() ? 0 : topicInfo.ledgerRanges
                                                 .lastKey();
                            LedgerRange lr = LedgerRange.newBuilder().setLedgerId(ledgerId)
                                             .setEndSeqIdIncluded(lastMessage.getMsgId()).build();
                            topicInfo.ledgerRanges.put(lr.getEndSeqIdIncluded().getLocalComponent(),
                                    new InMemoryLedgerRange(lr, prevLedgerEnd + 1, lh));

                            logger.info("Recovered unclosed ledger: " + ledgerId + " for topic: "
                                        + topic.toStringUtf8() + " with " + numEntriesInLastLedger + " entries");
View Full Code Here

                    topicInfo.lastSeqIdPushed = topicInfo.ledgerRanges.isEmpty() ? MessageSeqId.newBuilder()
                                                .setLocalComponent(0).build() : topicInfo.ledgerRanges.lastEntry().getValue().range
                                                .getEndSeqIdIncluded();

                    LedgerRange lastRange = LedgerRange.newBuilder().setLedgerId(lh.getId()).build();
                    topicInfo.currentLedgerRange = new InMemoryLedgerRange(lastRange, topicInfo.lastSeqIdPushed
                            .getLocalComponent() + 1, lh);

                    // Persist the fact that we started this new
                    // ledger to ZK
View Full Code Here

TOP

Related Classes of org.apache.hedwig.protocol.PubSubProtocol.LedgerRange

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.