MockMetadata(LedgerMetadata toCopy) { ensembleSize = toCopy.getEnsembleSize(); writeQuorumSize = toCopy.getWriteQuorumSize(); ackQuorumSize = toCopy.getAckQuorumSize(); lastEntryId = toCopy.getLastEntryId(); length = toCopy.getLength(); digestType = toCopy.getDigestType(); ctime = toCopy.getCtime(); isClosed = toCopy.isClosed(); customMetadata = ImmutableMap.copyOf(toCopy.getCustomMetadata()); }
return ThreadLocalRandom.current().nextInt() % metadata.getEnsembleSize(); } else { return (currentStickyBookieIndex.get() + 1) % metadata.getEnsembleSize();
TryReadLastConfirmedOp(LedgerHandle lh, BookieClient bookieClient, List<BookieSocketAddress> ensemble, LastConfirmedDataCallback cb, long lac) { this.lh = lh; this.bookieClient = bookieClient; this.cb = cb; this.maxRecoveredData = new RecoveryData(lac, 0); this.numResponsesPending = lh.getLedgerMetadata().getEnsembleSize(); this.currentEnsemble = ensemble; }
writer.append(String.valueOf(metadata.getEnsembleSize())).append(LINE_SPLITTER); writer.append(String.valueOf(metadata.getLength())).append(LINE_SPLITTER);
/** * Send to next replica speculatively, if required and possible. * This returns the host we may have sent to for unit testing. * @return host we sent to if we sent. null otherwise. */ @Override synchronized BookieSocketAddress maybeSendSpeculativeRead(BitSet heardFrom) { if (nextReplicaIndexToReadFrom >= getLedgerMetadata().getEnsembleSize()) { return null; } BitSet sentTo = getSentToBitSet(); sentTo.and(heardFrom); // only send another read, if we have had no response at all (even for other entries) // from any of the other bookies we have sent the request to if (sentTo.cardinality() == 0) { return sendNextRead(); } else { return null; } }
public ReadLastConfirmedOp(LedgerHandle lh, BookieClient bookieClient, List<BookieSocketAddress> ensemble, LastConfirmedDataCallback cb) { this.cb = cb; this.bookieClient = bookieClient; this.maxRecoveredData = new RecoveryData(LedgerHandle.INVALID_ENTRY_ID, 0); this.lh = lh; this.numResponsesPending = lh.getLedgerMetadata().getEnsembleSize(); this.coverageSet = lh.distributionSchedule.getCoverageSet(); this.currentEnsemble = ensemble; }
List<BookieSocketAddress> newEnsemble = new ArrayList<>(oldEnsemble); int ensembleSize = metadata.getEnsembleSize(); int writeQ = metadata.getWriteQuorumSize(); int ackQ = metadata.getAckQuorumSize();
PendingReadOp(LedgerHandle lh, ClientContext clientCtx, long startEntryId, long endEntryId, boolean isRecoveryRead) { this.seq = new ArrayList<>((int) ((endEntryId + 1) - startEntryId)); this.future = new CompletableFuture<>(); this.lh = lh; this.clientCtx = clientCtx; this.startEntryId = startEntryId; this.endEntryId = endEntryId; this.isRecoveryRead = isRecoveryRead; this.allowFailFast = false; numPendingEntries = endEntryId - startEntryId + 1; requiredBookiesMissingEntryForRecovery = getLedgerMetadata().getWriteQuorumSize() - getLedgerMetadata().getAckQuorumSize() + 1; heardFromHosts = new HashSet<>(); heardFromHostsBitSet = new BitSet(getLedgerMetadata().getEnsembleSize()); }
synchronized BookieSocketAddress sendNextRead() { if (nextReplicaIndexToReadFrom >= getLedgerMetadata().getEnsembleSize()) { // we are done, the read has failed from all replicas, just fail the // read // Do it a bit pessimistically, only when finished trying all replicas // to check whether we received more missed reads than requiredBookiesMissingEntryForRecovery if (BKException.Code.BookieHandleNotAvailableException == firstError && numMissedEntryReads > maxMissedReadsAllowed) { firstError = BKException.Code.NoSuchEntryException; } fail(firstError); return null; } int replica = nextReplicaIndexToReadFrom; int bookieIndex = orderedEnsemble.get(nextReplicaIndexToReadFrom); nextReplicaIndexToReadFrom++; try { BookieSocketAddress to = ensemble.get(bookieIndex); sendReadTo(bookieIndex, to, this); sentReplicas.set(replica); return to; } catch (InterruptedException ie) { LOG.error("Interrupted reading entry " + this, ie); Thread.currentThread().interrupt(); fail(BKException.Code.InterruptedException); return null; } }
ReadLastConfirmedAndEntryOp(LedgerHandle lh, ClientContext clientCtx, List<BookieSocketAddress> ensemble, LastConfirmedAndEntryCallback cb, long prevEntryId, long timeOutInMillis) { this.lh = lh; this.clientCtx = clientCtx; this.cb = cb; this.prevEntryId = prevEntryId; this.lastAddConfirmed = lh.getLastAddConfirmed(); this.timeOutInMillis = timeOutInMillis; this.numResponsesPending = 0; this.currentEnsemble = ensemble; // since long poll is effectively reading lac with waits, lac can be potentially // be advanced in different write quorums, so we need to make sure to cover enough // bookies before claiming lac is not advanced. this.numEmptyResponsesAllowed = getLedgerMetadata().getEnsembleSize() - getLedgerMetadata().getAckQuorumSize() + 1; this.requestTimeNano = MathUtils.nowInNano(); maxMissedReadsAllowed = getLedgerMetadata().getEnsembleSize() - getLedgerMetadata().getAckQuorumSize(); heardFromHostsBitSet = new BitSet(getLedgerMetadata().getEnsembleSize()); emptyResponsesFromHostsBitSet = new BitSet(getLedgerMetadata().getEnsembleSize()); }
private static boolean areEntriesOfSegmentStoredInTheBookie(LedgerMetadata ledgerMetadata, BookieSocketAddress bookieAddress, int segmentNo) { boolean isLedgerClosed = ledgerMetadata.isClosed(); int ensembleSize = ledgerMetadata.getEnsembleSize(); int writeQuorumSize = ledgerMetadata.getWriteQuorumSize(); ledgerMetadata.getEnsembleSize()); List<BookieSocketAddress> currentSegmentEnsemble = segments.get(segmentNo).getValue(); int thisBookieIndexInCurrentEnsemble = currentSegmentEnsemble.indexOf(bookieAddress);
EnsemblePlacementPolicy.PlacementResult<BookieSocketAddress> replaceBookieResponse = bkc.getPlacementPolicy().replaceBookie( lh.getLedgerMetadata().getEnsembleSize(), lh.getLedgerMetadata().getWriteQuorumSize(), lh.getLedgerMetadata().getAckQuorumSize(),
public static LedgerMetadataBuilder from(LedgerMetadata other) { LedgerMetadataBuilder builder = new LedgerMetadataBuilder(); builder.metadataFormatVersion = other.getMetadataFormatVersion(); builder.ensembleSize = other.getEnsembleSize(); builder.writeQuorumSize = other.getWriteQuorumSize(); builder.ackQuorumSize = other.getAckQuorumSize(); builder.state = other.getState(); if (builder.state == State.CLOSED) { builder.lastEntryId = Optional.of(other.getLastEntryId()); builder.length = Optional.of(other.getLength()); } builder.ensembles.putAll(other.getAllEnsembles()); if (other.hasPassword()) { builder.password = Optional.of(other.getPassword()); builder.digestType = Optional.of(other.getDigestType()); } builder.ctime = other.getCtime(); /** Hack to get around fact that ctime was never versioned correctly */ builder.storeCtime = LedgerMetadataUtils.shouldStoreCtime(other); builder.customMetadata = ImmutableMap.copyOf(other.getCustomMetadata()); return builder; }
builder.setQuorumSize(metadata.getWriteQuorumSize()) .setAckQuorumSize(metadata.getAckQuorumSize()) .setEnsembleSize(metadata.getEnsembleSize()) .setLength(metadata.getLength()) .setLastEntryId(metadata.getLastEntryId());
builder.setQuorumSize(metadata.getWriteQuorumSize()) .setAckQuorumSize(metadata.getAckQuorumSize()) .setEnsembleSize(metadata.getEnsembleSize()) .setLength(metadata.getLength()) .setLastEntryId(metadata.getLastEntryId());
&& getLedgerMetadata().getEnsembleSize() == getLedgerMetadata().getWriteQuorumSize()) { stickyBookieIndex = clientCtx.getPlacementPolicy().getStickyReadBookieIndex(metadata, Optional.empty()); } else { metadata.getWriteQuorumSize(), metadata.getAckQuorumSize(), metadata.getEnsembleSize()); this.bookieFailureHistory = CacheBuilder.newBuilder() .expireAfterWrite(clientCtx.getConf().bookieFailureHistoryExpirationMSec, TimeUnit.MILLISECONDS)