You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@ratis.apache.org by "Glen Geng (Jira)" <ji...@apache.org> on 2021/04/26 03:54:00 UTC

[jira] [Updated] (RATIS-1369) When there is no snapshot, the return snapshotIndex should be -1, not 0.

     [ https://issues.apache.org/jira/browse/RATIS-1369?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Glen Geng updated RATIS-1369:
-----------------------------
    Description: 
For now, if there is no snapshot existed, the returned snapshotIndex is 0. It is not correctly, since the raft log starts from index 0, a snapshot taken at snapshotIndex 0 should contain the log entry 0. The snapshotIndex for nn empty/fake snapshot should be -1.
{code:java}
diff --git a/ratis-server/src/main/java/org/apache/ratis/server/impl/ServerState.java b/ratis-server/src/main/java/org/apache/ratis/server/impl/ServerState.java
index 728f7e9c..6307ca79 100644
--- a/ratis-server/src/main/java/org/apache/ratis/server/impl/ServerState.java
+++ b/ratis-server/src/main/java/org/apache/ratis/server/impl/ServerState.java
@@ -431,7 +431,7 @@ class ServerState implements Closeable {
 
   long getLatestInstalledSnapshotIndex() {
     final TermIndex ti = latestInstalledSnapshot.get();
-    return ti != null? ti.getIndex(): 0L;
+    return ti != null? ti.getIndex(): -1L;
   }
 
   /**
@@ -440,7 +440,7 @@ class ServerState implements Closeable {
    */
   long getSnapshotIndex() {
     final SnapshotInfo s = getLatestSnapshot();
-    final long latestSnapshotIndex = s != null ? s.getIndex() : 0;
+    final long latestSnapshotIndex = s != null ? s.getIndex() : -1;
     return Math.max(latestSnapshotIndex, getLatestInstalledSnapshotIndex());
   }
{code}
This issue is found in bootstrap SCM in SCM HA.

 

 

 

 

> When there is no snapshot, the return snapshotIndex should be -1, not 0.
> ------------------------------------------------------------------------
>
>                 Key: RATIS-1369
>                 URL: https://issues.apache.org/jira/browse/RATIS-1369
>             Project: Ratis
>          Issue Type: Bug
>          Components: server
>            Reporter: Glen Geng
>            Assignee: Glen Geng
>            Priority: Major
>
> For now, if there is no snapshot existed, the returned snapshotIndex is 0. It is not correctly, since the raft log starts from index 0, a snapshot taken at snapshotIndex 0 should contain the log entry 0. The snapshotIndex for nn empty/fake snapshot should be -1.
> {code:java}
> diff --git a/ratis-server/src/main/java/org/apache/ratis/server/impl/ServerState.java b/ratis-server/src/main/java/org/apache/ratis/server/impl/ServerState.java
> index 728f7e9c..6307ca79 100644
> --- a/ratis-server/src/main/java/org/apache/ratis/server/impl/ServerState.java
> +++ b/ratis-server/src/main/java/org/apache/ratis/server/impl/ServerState.java
> @@ -431,7 +431,7 @@ class ServerState implements Closeable {
>  
>    long getLatestInstalledSnapshotIndex() {
>      final TermIndex ti = latestInstalledSnapshot.get();
> -    return ti != null? ti.getIndex(): 0L;
> +    return ti != null? ti.getIndex(): -1L;
>    }
>  
>    /**
> @@ -440,7 +440,7 @@ class ServerState implements Closeable {
>     */
>    long getSnapshotIndex() {
>      final SnapshotInfo s = getLatestSnapshot();
> -    final long latestSnapshotIndex = s != null ? s.getIndex() : 0;
> +    final long latestSnapshotIndex = s != null ? s.getIndex() : -1;
>      return Math.max(latestSnapshotIndex, getLatestInstalledSnapshotIndex());
>    }
> {code}
> This issue is found in bootstrap SCM in SCM HA.
>  
>  
>  
>  



--
This message was sent by Atlassian Jira
(v8.3.4#803005)