perf: apply committed raft entries via raft-log-from, not full-log scans
ober
3189fb14b148eb1b25f96d5a9ed25d23fe469d63
--- a/lib/jerboa-db/cluster.ss +++ b/lib/jerboa-db/cluster.ss @@ -90,10 +90,7 @@ (if leader (if (= n 1) ;; Single-node: highest log index = effective commit index. - (let ([log (raft-log leader)]) - (if (null? log) - 0 - (log-entry-index (car (last-pair log))))) + (raft-log-last-index leader) (raft-commit-index leader)) 0))) @@ -131,7 +128,7 @@ (replication-set-last-applied-index! state entry-index))) ;; Non-transaction commands are intentionally skipped. (replication-set-last-applied-index! state entry-index))))) - (raft-log leader)))))) + (raft-log-from leader (+ last-applied 1))))))) ;; start-cluster-apply-fiber! : conn replication-state raft-cluster -> thread ;; --- a/lib/jerboa-db/replication.ss +++ b/lib/jerboa-db/replication.ss @@ -274,8 +274,9 @@ [commit-index (raft-commit-index node)] [last-applied (replication-state-last-applied-index state)] [applied-count 0]) - ;; raft-log returns the list of ALL log entries (both committed and possibly - ;; uncommitted tail). We process only entries whose index <= commit-index. + ;; raft-log-from returns only the entries beyond last-applied (both + ;; committed and possibly an uncommitted tail). We process only entries + ;; whose index <= commit-index. ;; ;; (std raft) stores entries as log-entry records and exports checked ;; accessors for consumers; no record-layout reflection is required. @@ -312,7 +313,7 @@ (set! applied-count (+ applied-count 1)))) ;; Non-transaction commands are intentionally skipped. (replication-state-last-applied-index-set! state entry-index))))) - (raft-log node)) + (raft-log-from node (+ last-applied 1))) applied-count)) ;; ========================================================================= @@ -348,7 +349,7 @@ (set! delivered (+ delivered 1))) ;; Non-transaction commands are intentionally skipped. (replication-state-last-applied-index-set! state entry-index))))) - (raft-log node)) + (raft-log-from node (+ last-applied 1))) delivered)) ;; replication-last-applied-index : replication-state -> integer