/** * Creates a new instance of the LogMetadata class with one Ledger and epoch set to the default value. * * @param initialLedgerId The Id of the Ledger to start the log with. */ LogMetadata(long initialLedgerId) { this(INITIAL_EPOCH, true, Collections.singletonList(new LedgerMetadata(initialLedgerId, INITIAL_LEDGER_SEQUENCE)), INITIAL_TRUNCATION_ADDRESS, INITIAL_VERSION); }
TestWriteLedger(int ledgerId) { super(null, new LedgerMetadata(ledgerId, ledgerId)); } }
/** * Creates a new instance of the LogMetadata class which contains an additional ledger. * * @param ledgerId The Id of the Ledger to add. * @return A new instance of the LogMetadata class. */ LogMetadata addLedger(long ledgerId) { Preconditions.checkState(this.enabled, "Log is not enabled. Cannot perform any modifications on it."); // Copy existing ledgers. List<LedgerMetadata> newLedgers = new ArrayList<>(this.ledgers.size() + 1); newLedgers.addAll(this.ledgers); // Create and add metadata for the new ledger. int sequence = this.ledgers.size() == 0 ? INITIAL_LEDGER_SEQUENCE : this.ledgers.get(this.ledgers.size() - 1).getSequence() + 1; newLedgers.add(new LedgerMetadata(ledgerId, sequence)); return new LogMetadata(this.epoch + 1, this.enabled, Collections.unmodifiableList(newLedgers), this.truncationAddress, this.updateVersion.get()); }
/** * Updates the LastAddConfirmed on individual LedgerMetadata instances based on the provided argument. * * @param lastAddConfirmed A Map of LedgerId to LastAddConfirmed based on which we can update the status. * @return This (unmodified) instance if lastAddConfirmed.isEmpty() or a new instance of the LogMetadata class with * the updated LedgerMetadata instances. */ LogMetadata updateLedgerStatus(Map<Long, Long> lastAddConfirmed) { if (lastAddConfirmed.isEmpty()) { // Nothing to change. return this; } val newLedgers = this.ledgers.stream() .map(lm -> { long lac = lastAddConfirmed.getOrDefault(lm.getLedgerId(), Long.MIN_VALUE); if (lm.getStatus() == LedgerMetadata.Status.Unknown && lac != Long.MIN_VALUE) { LedgerMetadata.Status e = lac == Ledgers.NO_ENTRY_ID ? LedgerMetadata.Status.Empty : LedgerMetadata.Status.NotEmpty; lm = new LedgerMetadata(lm.getLedgerId(), lm.getSequence(), e); } return lm; }) .collect(Collectors.toList()); return new LogMetadata(this.epoch, this.enabled, Collections.unmodifiableList(newLedgers), this.truncationAddress, this.updateVersion.get()); }
private LedgerMetadata readLedger00(RevisionDataInput input) throws IOException { long ledgerId = input.readCompactLong(); int seq = input.readCompactInt(); LedgerMetadata.Status empty = LedgerMetadata.Status.valueOf(input.readByte()); return new LedgerMetadata(ledgerId, seq, empty); } }