X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-akka-raft%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fraft%2FAbstractReplicatedLogImpl.java;h=c245206f641f3a4ff31da8608076f1c3d68cb4f6;hb=61e85d54cfcd70053993f910092eba1ab3fcc850;hp=b4b2afbc4ad602ccd1bc9f50da8641cd0b05f605;hpb=dea515c8870769408b9bea29f555d6b71ff43211;p=controller.git diff --git a/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/AbstractReplicatedLogImpl.java b/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/AbstractReplicatedLogImpl.java index b4b2afbc4a..c245206f64 100644 --- a/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/AbstractReplicatedLogImpl.java +++ b/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/AbstractReplicatedLogImpl.java @@ -124,20 +124,43 @@ public abstract class AbstractReplicatedLogImpl implements ReplicatedLog { @Override public List getFrom(long logEntryIndex) { - return getFrom(logEntryIndex, journal.size()); + return getFrom(logEntryIndex, journal.size(), NO_MAX_SIZE); } @Override - public List getFrom(long logEntryIndex, int max) { + public List getFrom(long logEntryIndex, int maxEntries, long maxDataSize) { int adjustedIndex = adjustedIndex(logEntryIndex); int size = journal.size(); if (adjustedIndex >= 0 && adjustedIndex < size) { // physical index should be less than list size and >= 0 - int maxIndex = adjustedIndex + max; + int maxIndex = adjustedIndex + maxEntries; if(maxIndex > size){ maxIndex = size; } - return new ArrayList<>(journal.subList(adjustedIndex, maxIndex)); + + if(maxDataSize == NO_MAX_SIZE) { + return new ArrayList<>(journal.subList(adjustedIndex, maxIndex)); + } else { + List retList = new ArrayList<>(maxIndex - adjustedIndex); + long totalSize = 0; + for(int i = adjustedIndex; i < maxIndex; i++) { + ReplicatedLogEntry entry = journal.get(i); + totalSize += entry.size(); + if(totalSize <= maxDataSize) { + retList.add(entry); + } else { + if(retList.isEmpty()) { + // Edge case - the first entry's size exceeds the threshold. We need to return + // at least the first entry so add it here. + retList.add(entry); + } + + break; + } + } + + return retList; + } } else { return Collections.emptyList(); }