Skip to content

Commit 8b37d12

Browse files
committed
address PR comments
1 parent 2ff19d1 commit 8b37d12

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

session-state-machine/src/main/scala/zio/raft/sessionstatemachine/SessionStateMachine.scala

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,28 @@ import zio.raft.protocol.RequestId.RequestIdSyntax
88
import zio.stream.Stream
99
import java.time.Instant
1010

11-
/** Abstract base class for session-aware state machines using the template pattern.
11+
/** Trait for session-aware state machines using the template pattern.
1212
*
13-
* This class implements Chapter 6.3 of the Raft dissertation (Implementing linearizable semantics) by providing
13+
* This trait implements Chapter 6.3 of the Raft dissertation (Implementing linearizable semantics) by providing
1414
* automatic session management, idempotency checking, and response caching.
1515
*
1616
* ## Template Pattern
1717
*
18-
* Users extend this class and implement 3 protected abstract methods:
18+
* Users extend this trait and implement 3 protected abstract methods:
1919
* - `applyCommand`: Business logic for processing user commands (returns StateWriter)
2020
* - `handleSessionCreated`: Session initialization logic (returns StateWriter)
2121
* - `handleSessionExpired`: Session cleanup logic (returns StateWriter)
2222
*
2323
* The StateWriter monad combines State for state transitions with Writer for accumulating server-initiated requests.
2424
* Users call `.log(serverRequest)` to emit server requests instead of manually collecting them in tuples.
2525
*
26-
* The base class provides the final `apply` template method that orchestrates:
26+
* This trait provides the final `apply` template method that orchestrates:
2727
* - Idempotency checking via (sessionId, requestId) pairs
2828
* - Response caching for duplicate requests
2929
* - Server-initiated request management with cumulative acknowledgment
3030
* - Session lifecycle coordination
31-
* - State narrowing (users see only HMap[UserSchema])
32-
* - State merging (user changes merged back to combined state)
31+
* - Cache cleanup driven by client-provided lowestRequestId (inclusive: removes requestId <= lowestRequestId)
32+
* - Evicted response detection: if requestId <= highestLowestRequestIdSeen and not in cache, return RequestError.ResponseEvicted
3333
*
3434
* ## Type Parameters
3535
*
@@ -86,7 +86,7 @@ trait SessionStateMachine[UC <: Command, R, SR, UserSchema <: Tuple]
8686
/** Apply a user command to the state.
8787
*
8888
* This method receives ONLY the user schema state (UserSchema), not session management state. Session management
89-
* prefixes are handled by the base class automatically.
89+
* prefixes are handled by this trait automatically.
9090
*
9191
* Use `.log(serverRequest)` to emit server-initiated requests. Server requests MUST be wrapped in
9292
* ServerRequestForSession to specify target sessionId. This allows sending requests to ANY session, not just the
@@ -175,7 +175,7 @@ trait SessionStateMachine[UC <: Command, R, SR, UserSchema <: Tuple]
175175
* @note
176176
* Receives complete schema state
177177
* @note
178-
* Session metadata and cache are automatically removed by base class
178+
* Session metadata and cache are automatically removed by this trait
179179
* @note
180180
* Must be pure and deterministic
181181
* @note
@@ -188,7 +188,7 @@ trait SessionStateMachine[UC <: Command, R, SR, UserSchema <: Tuple]
188188
): StateWriter[HMap[Schema], ServerRequestForSession[SR], Unit]
189189

190190
// ====================================================================================
191-
// StateMachine INTERFACE - Implemented by base class
191+
// StateMachine INTERFACE - Implemented by this trait
192192
// ====================================================================================
193193

194194
/** Empty state with no sessions or data.
@@ -429,7 +429,7 @@ trait SessionStateMachine[UC <: Command, R, SR, UserSchema <: Tuple]
429429
/** Add server requests to state and assign monotonically increasing IDs.
430430
*
431431
* Each request is stored with a composite key (SessionId, RequestId) for efficiency. sessionId comes from
432-
* ServerRequestForSession, not as a parameter!
432+
* ServerRequestForSession.
433433
*
434434
* @param createdAt
435435
* Timestamp when the command was created (for lastSentAt)

session-state-machine/src/main/scala/zio/raft/sessionstatemachine/package.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ import java.time.Instant
77

88
/** Session State Machine Framework package.
99
*
10-
* This package provides the SessionStateMachine abstract base class and related types for implementing linearizable,
11-
* exactly-once state machines based on Chapter 6.3 of the Raft dissertation.
10+
* This package provides the SessionStateMachine trait and related types for implementing linearizable, exactly-once
11+
* state machines based on Chapter 6.3 of the Raft dissertation.
1212
*
1313
* Key types:
14-
* - SessionStateMachine: Abstract base class (template pattern)
14+
* - SessionStateMachine: Trait using template pattern
1515
* - SessionSchema: Fixed 4-prefix schema for session management
1616
* - Schema: Type-level concatenation of SessionSchema + UserSchema
1717
* - SessionCommand: ADT of commands the session state machine accepts

0 commit comments

Comments
 (0)