You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@asterixdb.apache.org by AsterixDB Code Review <do...@asterix-gerrit.ics.uci.edu> on 2021/09/02 10:26:37 UTC

Change in asterixdb[master]: [NO ISSUE][REP] Add replica sync progress

From Murtadha Hubail <mh...@apache.org>:

Murtadha Hubail has uploaded this change for review. ( https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/13063 )


Change subject: [NO ISSUE][REP] Add replica sync progress
......................................................................

[NO ISSUE][REP] Add replica sync progress

- user model changes: no
- storage format changes: no
- interface changes: yes

Details:

- Add replica sync progress based on the replica missing
  files.
- Add replica last progress timestamp that can be used
  to determine replica progress inactivity.

Change-Id: Iab2cd7e745c4150e2d0aef3af864ec0f66dd96e7
---
M asterixdb/asterix-common/src/main/java/org/apache/asterix/common/replication/IPartitionReplica.java
M asterixdb/asterix-replication/src/main/java/org/apache/asterix/replication/api/PartitionReplica.java
M asterixdb/asterix-replication/src/main/java/org/apache/asterix/replication/sync/ReplicaFilesSynchronizer.java
3 files changed, 51 insertions(+), 1 deletion(-)



  git pull ssh://asterix-gerrit.ics.uci.edu:29418/asterixdb refs/changes/63/13063/1

diff --git a/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/replication/IPartitionReplica.java b/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/replication/IPartitionReplica.java
index 761b2c6..dd3c00b 100644
--- a/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/replication/IPartitionReplica.java
+++ b/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/replication/IPartitionReplica.java
@@ -22,6 +22,8 @@
 
 public interface IPartitionReplica {
 
+    long getLastProgressTime();
+
     enum PartitionReplicaStatus {
         /* replica is in-sync with master */
         IN_SYNC,
@@ -51,4 +53,11 @@
      * @param failure
      */
     void notifyFailure(Exception failure);
+
+    /**
+     * Gets the current sync progress
+     *
+     * @return the current sync progress
+     */
+    double getSyncProgress();
 }
diff --git a/asterixdb/asterix-replication/src/main/java/org/apache/asterix/replication/api/PartitionReplica.java b/asterixdb/asterix-replication/src/main/java/org/apache/asterix/replication/api/PartitionReplica.java
index 282d475..e265d03 100644
--- a/asterixdb/asterix-replication/src/main/java/org/apache/asterix/replication/api/PartitionReplica.java
+++ b/asterixdb/asterix-replication/src/main/java/org/apache/asterix/replication/api/PartitionReplica.java
@@ -52,6 +52,8 @@
     private static final int INITIAL_BUFFER_SIZE = StorageUtil.getIntSizeInBytes(4, StorageUtil.StorageUnit.KILOBYTE);
     private final INcApplicationContext appCtx;
     private final ReplicaIdentifier id;
+    private double syncProgress = -1;
+    private long lastProgressTime = -1;
     private ByteBuffer reusbaleBuf;
     private PartitionReplicaStatus status = DISCONNECTED;
     private ISocketChannel sc;
@@ -133,6 +135,16 @@
         return reusbaleBuf;
     }
 
+    public synchronized void setSyncProgress(double syncProgress) {
+        this.syncProgress = syncProgress;
+        lastProgressTime = System.nanoTime();
+    }
+
+    @Override
+    public synchronized double getSyncProgress() {
+        return syncProgress;
+    }
+
     private JsonNode asJson() {
         ObjectNode json = OBJECT_MAPPER.createObjectNode();
         json.put("id", id.toString());
@@ -153,6 +165,19 @@
     }
 
     @Override
+    public synchronized long getLastProgressTime() {
+        switch (status) {
+            case IN_SYNC:
+                return System.nanoTime();
+            case CATCHING_UP:
+                return lastProgressTime;
+            case DISCONNECTED:
+                return -1;
+        }
+        return -1;
+    }
+
+    @Override
     public int hashCode() {
         return id.hashCode();
     }
@@ -172,6 +197,17 @@
         }
         LOGGER.info(() -> "Replica " + this + " status changing: " + this.status + " -> " + status);
         this.status = status;
+        switch (status) {
+            case IN_SYNC:
+                syncProgress = 1;
+                break;
+            case CATCHING_UP:
+                lastProgressTime = System.nanoTime();
+                break;
+            case DISCONNECTED:
+                syncProgress = -1;
+                break;
+        }
     }
 
     private void sendGoodBye() {
diff --git a/asterixdb/asterix-replication/src/main/java/org/apache/asterix/replication/sync/ReplicaFilesSynchronizer.java b/asterixdb/asterix-replication/src/main/java/org/apache/asterix/replication/sync/ReplicaFilesSynchronizer.java
index 3c93d17..faf3f54 100644
--- a/asterixdb/asterix-replication/src/main/java/org/apache/asterix/replication/sync/ReplicaFilesSynchronizer.java
+++ b/asterixdb/asterix-replication/src/main/java/org/apache/asterix/replication/sync/ReplicaFilesSynchronizer.java
@@ -105,7 +105,12 @@
         final FileSynchronizer sync = new FileSynchronizer(appCtx, replica);
         // sort files to ensure index metadata files starting with "." are replicated first
         files.sort(String::compareTo);
-        files.forEach(sync::replicate);
+        int missingFilesCount = files.size();
+        for (int i = 0; i < missingFilesCount; i++) {
+            String file = files.get(i);
+            sync.replicate(file);
+            replica.setSyncProgress((i + 1d) / missingFilesCount);
+        }
     }
 
     private void deleteInvalidFiles(List<String> files) {

-- 
To view, visit https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/13063
To unsubscribe, or for help writing mail filters, visit https://asterix-gerrit.ics.uci.edu/settings

Gerrit-Project: asterixdb
Gerrit-Branch: master
Gerrit-Change-Id: Iab2cd7e745c4150e2d0aef3af864ec0f66dd96e7
Gerrit-Change-Number: 13063
Gerrit-PatchSet: 1
Gerrit-Owner: Murtadha Hubail <mh...@apache.org>
Gerrit-MessageType: newchange

Change in asterixdb[master]: [NO ISSUE][REP] Add replica sync progress

Posted by AsterixDB Code Review <do...@asterix-gerrit.ics.uci.edu>.
From Jenkins <je...@fulliautomatix.ics.uci.edu>:

Jenkins has posted comments on this change. ( https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/13063 )

Change subject: [NO ISSUE][REP] Add replica sync progress
......................................................................


Patch Set 2: Integration-Tests+1

Integration Tests Successful

https://asterix-jenkins.ics.uci.edu/job/asterix-gerrit-integration-tests/12440/ : SUCCESS


-- 
To view, visit https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/13063
To unsubscribe, or for help writing mail filters, visit https://asterix-gerrit.ics.uci.edu/settings

Gerrit-Project: asterixdb
Gerrit-Branch: master
Gerrit-Change-Id: Iab2cd7e745c4150e2d0aef3af864ec0f66dd96e7
Gerrit-Change-Number: 13063
Gerrit-PatchSet: 2
Gerrit-Owner: Murtadha Hubail <mh...@apache.org>
Gerrit-Reviewer: Jenkins <je...@fulliautomatix.ics.uci.edu>
Gerrit-CC: Anon. E. Moose #1000171
Gerrit-Comment-Date: Thu, 02 Sep 2021 12:27:23 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment

Change in asterixdb[master]: [NO ISSUE][REP] Add replica sync progress

Posted by AsterixDB Code Review <do...@asterix-gerrit.ics.uci.edu>.
From Murtadha Hubail <mh...@apache.org>:

Murtadha Hubail has uploaded this change for review. ( https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/13063 )


Change subject: [NO ISSUE][REP] Add replica sync progress
......................................................................

[NO ISSUE][REP] Add replica sync progress

- user model changes: no
- storage format changes: no
- interface changes: yes

Details:

- Add replica sync progress based on the replica missing
  files.
- Add replica last progress timestamp that can be used
  to determine replica progress inactivity.

Change-Id: Iab2cd7e745c4150e2d0aef3af864ec0f66dd96e7
---
M asterixdb/asterix-common/src/main/java/org/apache/asterix/common/replication/IPartitionReplica.java
M asterixdb/asterix-replication/src/main/java/org/apache/asterix/replication/api/PartitionReplica.java
M asterixdb/asterix-replication/src/main/java/org/apache/asterix/replication/sync/ReplicaFilesSynchronizer.java
3 files changed, 51 insertions(+), 1 deletion(-)



  git pull ssh://asterix-gerrit.ics.uci.edu:29418/asterixdb refs/changes/63/13063/1

diff --git a/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/replication/IPartitionReplica.java b/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/replication/IPartitionReplica.java
index 761b2c6..dd3c00b 100644
--- a/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/replication/IPartitionReplica.java
+++ b/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/replication/IPartitionReplica.java
@@ -22,6 +22,8 @@
 
 public interface IPartitionReplica {
 
+    long getLastProgressTime();
+
     enum PartitionReplicaStatus {
         /* replica is in-sync with master */
         IN_SYNC,
@@ -51,4 +53,11 @@
      * @param failure
      */
     void notifyFailure(Exception failure);
+
+    /**
+     * Gets the current sync progress
+     *
+     * @return the current sync progress
+     */
+    double getSyncProgress();
 }
diff --git a/asterixdb/asterix-replication/src/main/java/org/apache/asterix/replication/api/PartitionReplica.java b/asterixdb/asterix-replication/src/main/java/org/apache/asterix/replication/api/PartitionReplica.java
index 282d475..e265d03 100644
--- a/asterixdb/asterix-replication/src/main/java/org/apache/asterix/replication/api/PartitionReplica.java
+++ b/asterixdb/asterix-replication/src/main/java/org/apache/asterix/replication/api/PartitionReplica.java
@@ -52,6 +52,8 @@
     private static final int INITIAL_BUFFER_SIZE = StorageUtil.getIntSizeInBytes(4, StorageUtil.StorageUnit.KILOBYTE);
     private final INcApplicationContext appCtx;
     private final ReplicaIdentifier id;
+    private double syncProgress = -1;
+    private long lastProgressTime = -1;
     private ByteBuffer reusbaleBuf;
     private PartitionReplicaStatus status = DISCONNECTED;
     private ISocketChannel sc;
@@ -133,6 +135,16 @@
         return reusbaleBuf;
     }
 
+    public synchronized void setSyncProgress(double syncProgress) {
+        this.syncProgress = syncProgress;
+        lastProgressTime = System.nanoTime();
+    }
+
+    @Override
+    public synchronized double getSyncProgress() {
+        return syncProgress;
+    }
+
     private JsonNode asJson() {
         ObjectNode json = OBJECT_MAPPER.createObjectNode();
         json.put("id", id.toString());
@@ -153,6 +165,19 @@
     }
 
     @Override
+    public synchronized long getLastProgressTime() {
+        switch (status) {
+            case IN_SYNC:
+                return System.nanoTime();
+            case CATCHING_UP:
+                return lastProgressTime;
+            case DISCONNECTED:
+                return -1;
+        }
+        return -1;
+    }
+
+    @Override
     public int hashCode() {
         return id.hashCode();
     }
@@ -172,6 +197,17 @@
         }
         LOGGER.info(() -> "Replica " + this + " status changing: " + this.status + " -> " + status);
         this.status = status;
+        switch (status) {
+            case IN_SYNC:
+                syncProgress = 1;
+                break;
+            case CATCHING_UP:
+                lastProgressTime = System.nanoTime();
+                break;
+            case DISCONNECTED:
+                syncProgress = -1;
+                break;
+        }
     }
 
     private void sendGoodBye() {
diff --git a/asterixdb/asterix-replication/src/main/java/org/apache/asterix/replication/sync/ReplicaFilesSynchronizer.java b/asterixdb/asterix-replication/src/main/java/org/apache/asterix/replication/sync/ReplicaFilesSynchronizer.java
index 3c93d17..faf3f54 100644
--- a/asterixdb/asterix-replication/src/main/java/org/apache/asterix/replication/sync/ReplicaFilesSynchronizer.java
+++ b/asterixdb/asterix-replication/src/main/java/org/apache/asterix/replication/sync/ReplicaFilesSynchronizer.java
@@ -105,7 +105,12 @@
         final FileSynchronizer sync = new FileSynchronizer(appCtx, replica);
         // sort files to ensure index metadata files starting with "." are replicated first
         files.sort(String::compareTo);
-        files.forEach(sync::replicate);
+        int missingFilesCount = files.size();
+        for (int i = 0; i < missingFilesCount; i++) {
+            String file = files.get(i);
+            sync.replicate(file);
+            replica.setSyncProgress((i + 1d) / missingFilesCount);
+        }
     }
 
     private void deleteInvalidFiles(List<String> files) {

-- 
To view, visit https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/13063
To unsubscribe, or for help writing mail filters, visit https://asterix-gerrit.ics.uci.edu/settings

Gerrit-Project: asterixdb
Gerrit-Branch: master
Gerrit-Change-Id: Iab2cd7e745c4150e2d0aef3af864ec0f66dd96e7
Gerrit-Change-Number: 13063
Gerrit-PatchSet: 1
Gerrit-Owner: Murtadha Hubail <mh...@apache.org>
Gerrit-MessageType: newchange