szetszwo commented on code in PR #1332:
URL: https://github.com/apache/ratis/pull/1332#discussion_r2666027906


##########
ratis-docs/src/site/markdown/configurations.md:
##########
@@ -209,6 +209,14 @@ if it fails to receive any RPC responses from this peer 
within this specified ti
 | **Type**        | double, ranging from (0.0,1.0)                |
 | **Default**     | 0.9                                           |
 
+--------------------------------------------------------------------------------
+
+| **Property**    | `raft.server.read-index.use.applied-index.enabled`         
               |
+|:----------------|:--------------------------------------------------------------------------|
+| **Description** | whether leader return applied index instead of commit 
index for ReadIndex |

Review Comment:
   Let's don't mention `ReadIndex` since it is a kind of implementation 
details.  I suggest updating it to
   - `whether to enable applied index instead of using commit index for 
linearizable read`



##########
ratis-server-api/src/main/java/org/apache/ratis/server/RaftServerConfigKeys.java:
##########
@@ -265,6 +265,17 @@ static void setWriteIndexCacheExpiryTime(RaftProperties 
properties, TimeDuration
         setTimeDuration(properties::setTimeDuration, 
WRITE_INDEX_CACHE_EXPIRY_TIME_KEY, expiryTime);
       }
     }
+
+    interface ReadIndex {
+      String PREFIX = Read.PREFIX + ".read-index";
+
+      String READ_INDEX_USE_APPLIED_INDEX_ENABLED_KEY = PREFIX + 
".use.applied-index.enabled";

Review Comment:
   - Let's remove "`use`", i.e. `raft.server.read-index.applied-index.enabled`. 
   - The field names must be the same as the String value.  Otherwise, the 
TestConfUtils will fail as shown in the CI.
   - ~It needs a setter method.~
   
   ```java
       interface ReadIndex {
         String PREFIX = Read.PREFIX + ".read-index";
   
         String APPLIED_INDEX_ENABLED_KEY = PREFIX + ".applied-index.enabled";
         boolean APPLIED_INDEX_ENABLED_DEFAULT = false;
         static boolean appliedIndexEnabled(RaftProperties properties) {
           return getBoolean(properties::getBoolean, APPLIED_INDEX_ENABLED_KEY,
               APPLIED_INDEX_ENABLED_DEFAULT, getDefaultLog());
         }
   
         static void setAppliedIndexEnabled(RaftProperties properties, boolean 
enabled) {
           setBoolean(properties::setBoolean, APPLIED_INDEX_ENABLED_KEY, 
enabled);
         }
       }
   ```



##########
ratis-server/src/main/java/org/apache/ratis/server/impl/LeaderStateImpl.java:
##########
@@ -389,6 +390,8 @@ boolean isApplied() {
     } else {
       this.followerMaxGapThreshold = (long) (followerGapRatioMax * 
maxPendingRequests);
     }
+    this.readIndexUseAppliedIndexEnabled = RaftServerConfigKeys.Read.ReadIndex

Review Comment:
   Similarly, remove `use`.



##########
ratis-server/src/main/java/org/apache/ratis/server/impl/LeaderStateImpl.java:
##########
@@ -1134,21 +1137,23 @@ public boolean checkLeadership() {
   /**
    * Obtain the current readIndex for read only requests. See Raft paper 
section 6.4.
    * 1. Leader makes sure at least one log from current term is committed.
-   * 2. Leader record last committed index as readIndex.
+   * 2. Leader record last committed index or applied index (depending on 
configuration) as readIndex.
    * 3. Leader broadcast heartbeats to followers and waits for 
acknowledgements.
    * 4. If majority respond success, returns readIndex.
    * @return current readIndex.
    */
   CompletableFuture<Long> getReadIndex(Long readAfterWriteConsistentIndex) {
-    final long commitIndex = server.getRaftLog().getLastCommittedIndex();
+    final long lastAppliedOrCommitIndex = readIndexUseAppliedIndexEnabled ?

Review Comment:
   Let's just call it `index` instead of `lastAppliedOrCommitIndex`.



##########
ratis-docs/src/site/markdown/configurations.md:
##########
@@ -218,6 +218,13 @@ if it fails to receive any RPC responses from this peer 
within this specified ti
 | **Type**        | TimeDuration                                               
                    |
 | **Default**     | 60s                                                        
                    |
 
+### Read Index - Configurations related to ReadIndex used in linearizable read 
+
+| **Property**    | `raft.server.read.read-index.use.applied-index.enabled`    
               |
+|:----------------|:--------------------------------------------------------------------------|
+| **Description** | whether leader return applied index instead of commit 
index for ReadIndex |

Review Comment:
   Suggestion: "whether applied index (instead of commit index) is used for 
ReadIndex"



##########
ratis-docs/src/site/markdown/configurations.md:
##########
@@ -209,6 +209,14 @@ if it fails to receive any RPC responses from this peer 
within this specified ti
 | **Type**        | double, ranging from (0.0,1.0)                |
 | **Default**     | 0.9                                           |
 
+--------------------------------------------------------------------------------
+
+| **Property**    | `raft.server.read-index.use.applied-index.enabled`         
               |
+|:----------------|:--------------------------------------------------------------------------|
+| **Description** | whether leader return applied index instead of commit 
index for ReadIndex |

Review Comment:
   Let's don't mention `ReadIndex` since it is a kind of implementation 
details.  I suggest updating it to
   - `whether to enable applied index instead of using commit index for 
linearizable read`



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to