@Override public String toString() { return ServerProtoUtils.toLogEntryString(logEntry); } }
public static String toString(LogEntryProto... entries) { return entries == null? "null" : entries.length == 0 ? "[]" : entries.length == 1? toLogEntryString(entries[0]) : "" + Arrays.stream(entries).map(ServerProtoUtils::toLogEntryString) .collect(Collectors.toList()); }
public static String toString(LogEntryProto... entries) { return entries == null? "null" : entries.length == 0 ? "[]" : entries.length == 1? toLogEntryString(entries[0]) : "" + Arrays.stream(entries).map(ServerProtoUtils::toLogEntryString) .collect(Collectors.toList()); }
@Override public String toString() { return super.toString() + ": " + ServerProtoUtils.toLogEntryString(entry); } }
@Override public String toString() { return super.toString() + ": " + ServerProtoUtils.toLogEntryString(entry); } }
public String toDebugString() { final StringBuilder b = new StringBuilder() .append("startIndex=").append(startIndex) .append(", endIndex=").append(endIndex) .append(", numOfEntries=").append(numOfEntries()) .append(", isOpen? ").append(isOpen) .append(", file=").append(getSegmentFile()); records.stream().map(LogRecord::getTermIndex).forEach( ti -> b.append(" ").append(ti).append(", cache=") .append(ServerProtoUtils.toLogEntryString(entryCache.get(ti))) ); return b.toString(); }
public String toDebugString() { final StringBuilder b = new StringBuilder() .append("startIndex=").append(startIndex) .append(", endIndex=").append(endIndex) .append(", numOfEntries=").append(numOfEntries()) .append(", isOpen? ").append(isOpen) .append(", file=").append(getSegmentFile()); records.stream().map(LogRecord::getTermIndex).forEach( ti -> b.append(" ").append(ti).append(", cache=") .append(ServerProtoUtils.toLogEntryString(entryCache.get(ti))) ); return b.toString(); }
PendingRequest addPendingRequest(RaftClientRequest request, TransactionContext entry) { if (LOG.isDebugEnabled()) { LOG.debug("{}: addPendingRequest at {}, entry=", server.getId(), request, ServerProtoUtils.toLogEntryString(entry.getLogEntry())); } return pendingRequests.add(request, entry); }
public LogEntryProto getEntry(TimeDuration timeout) throws RaftLogIOException, TimeoutException { LogEntryProto entryProto; if (future == null) { return logEntry; } try { entryProto = future.thenApply(data -> ServerProtoUtils.addStateMachineData(data, logEntry)) .get(timeout.getDuration(), timeout.getUnit()); } catch (TimeoutException t) { throw t; } catch (Throwable t) { final String err = selfId + ": Failed readStateMachineData for " + ServerProtoUtils.toLogEntryString(logEntry); LogAppender.LOG.error(err, t); throw new RaftLogIOException(err, JavaUtils.unwrapCompletionException(t)); } // by this time we have already read the state machine data, // so the log entry data should be set now if (ServerProtoUtils.shouldReadStateMachineData(entryProto)) { final String err = selfId + ": State machine data not set for " + ServerProtoUtils.toLogEntryString(logEntry); LogAppender.LOG.error(err); throw new RaftLogIOException(err); } return entryProto; }
@Override public EntryWithData getEntryWithData(long index) throws RaftLogIOException { final LogEntryProto entry = get(index); if (!ServerProtoUtils.shouldReadStateMachineData(entry)) { return new EntryWithData(entry, null); } try { return new EntryWithData(entry, server.map(s -> s.getStateMachine().readStateMachineData(entry)).orElse(null)); } catch (Throwable e) { final String err = getSelfId() + ": Failed readStateMachineData for " + ServerProtoUtils.toLogEntryString(entry); LOG.error(err, e); throw new RaftLogIOException(err, JavaUtils.unwrapCompletionException(e)); } }
WriteLog(LogEntryProto entry) { this.entry = ServerProtoUtils.removeStateMachineData(entry); if (this.entry == entry || stateMachine == null) { this.stateMachineFuture = null; } else { try { // this.entry != entry iff the entry has state machine data this.stateMachineFuture = stateMachine.writeStateMachineData(entry); } catch (Throwable e) { LOG.error(name + ": writeStateMachineData failed for index " + entry.getIndex() + ", entry=" + ServerProtoUtils.toLogEntryString(entry), e); throw e; } } this.combined = stateMachineFuture == null? super.getFuture() : super.getFuture().thenCombine(stateMachineFuture, (index, stateMachineResult) -> index); }
private void put(LogEntryProto entry) { final LogEntryProto previous = indexMap.put(entry.getIndex(), entry); Preconditions.assertNull(previous, "previous"); final String s = entry.getStateMachineLogEntry().getLogData().toStringUtf8(); dataMap.put(s, entry); LOG.info("{}: put {}, {} -> {}", getId(), entry.getIndex(), s.length() <= 10? s: s.substring(0, 10) + "...", ServerProtoUtils.toLogEntryString(entry)); }
static void printLog(RaftLog log, Consumer<String> println) { if (log == null) { println.accept("log == null"); return; } final TermIndex last; final long flushed, committed; try(AutoCloseableLock readlock = log.readLock()) { last = log.getLastEntryTermIndex(); flushed = log.getLatestFlushedIndex(); committed = log.getLastCommittedIndex(); } final StringBuilder b = new StringBuilder(); for(long i = 0; i <= last.getIndex(); i++) { b.setLength(0); b.append(i == flushed? 'f': ' '); b.append(i == committed? 'c': ' '); b.append(String.format("%3d: ", i)); try { b.append(ServerProtoUtils.toLogEntryString(log.get(i))); } catch (RaftLogIOException e) { b.append(e); } println.accept(b.toString()); } } }
LOG.info("last = " + ServerProtoUtils.toLogEntryString(last)); Assert.assertNotNull(last); Assert.assertTrue(last.getIndex() <= leaderState.getLastAppliedIndex());
LOG.info("{}", ServerProtoUtils.toLogEntryString(e));
if (LOG.isTraceEnabled()) { LOG.trace("{}: appendEntry {}", getSelfId(), ServerProtoUtils.toLogEntryString(entry)); LOG.error(getSelfId() + ": Failed to append " + ServerProtoUtils.toLogEntryString(entry), throwable); throw throwable;
if (LOG.isTraceEnabled()) { LOG.trace("{}: appendEntry {}", server.getId(), ServerProtoUtils.toLogEntryString(entry));
LOG.info("{}: leader lastEntry entry[{}] = {}", leaderId, lastIndex, ServerProtoUtils.toLogEntryString(lastEntry)); Assert.assertTrue(lastEntry.hasMetadataEntry()); final long loggedCommitIndex = lastEntry.getMetadataEntry().getCommitIndex(); for(long i = lastIndex - 1; i > loggedCommitIndex; i--) { final LogEntryProto entry = leaderLog.get(i); LOG.info("{}: leader entry[{}] = {}", leaderId, i, ServerProtoUtils.toLogEntryString(entry)); Assert.assertFalse(entry.hasStateMachineLogEntry()); leaderId, loggedCommitIndex, ServerProtoUtils.toLogEntryString(lastCommittedEntry)); Assert.assertTrue(lastCommittedEntry.hasStateMachineLogEntry());