Search in sources :

Example 1 with TruncateIndices

use of org.apache.ratis.server.raftlog.segmented.SegmentedRaftLogCache.TruncateIndices in project incubator-ratis by apache.

the class SegmentedRaftLog method appendImpl.

@Override
public List<CompletableFuture<Long>> appendImpl(LogEntryProto... entries) {
    checkLogState();
    if (entries == null || entries.length == 0) {
        return Collections.emptyList();
    }
    try (AutoCloseableLock writeLock = writeLock()) {
        final TruncateIndices ti = cache.computeTruncateIndices(server::notifyTruncatedLogEntry, entries);
        final long truncateIndex = ti.getTruncateIndex();
        final int index = ti.getArrayIndex();
        LOG.debug("truncateIndex={}, arrayIndex={}", truncateIndex, index);
        final List<CompletableFuture<Long>> futures;
        if (truncateIndex != -1) {
            futures = new ArrayList<>(entries.length - index + 1);
            futures.add(truncate(truncateIndex));
        } else {
            futures = new ArrayList<>(entries.length - index);
        }
        for (int i = index; i < entries.length; i++) {
            futures.add(appendEntry(entries[i]));
        }
        return futures;
    }
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) AutoCloseableLock(org.apache.ratis.util.AutoCloseableLock) TruncateIndices(org.apache.ratis.server.raftlog.segmented.SegmentedRaftLogCache.TruncateIndices)

Aggregations

CompletableFuture (java.util.concurrent.CompletableFuture)1 TruncateIndices (org.apache.ratis.server.raftlog.segmented.SegmentedRaftLogCache.TruncateIndices)1 AutoCloseableLock (org.apache.ratis.util.AutoCloseableLock)1