Merge branch 'gerrit/trinity' into 'master'

Change-Id: Ib4f12c79fdfe5c0ba3a79c45b304e815a600b097
diff --git a/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/nc/IndexCheckpointManager.java b/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/nc/IndexCheckpointManager.java
index 2e43397..77a4f19 100644
--- a/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/nc/IndexCheckpointManager.java
+++ b/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/nc/IndexCheckpointManager.java
@@ -129,6 +129,11 @@
     }
 
     @Override
+    public synchronized boolean isValidIndex() throws HyracksDataException {
+        return getCheckpointCount() > 0;
+    }
+
+    @Override
     public long getValidComponentSequence() throws HyracksDataException {
         if (getCheckpointCount() > 0) {
             return getLatest().getValidComponentSequence();
diff --git a/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/storage/IIndexCheckpointManager.java b/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/storage/IIndexCheckpointManager.java
index c43f4f0..75557ec 100644
--- a/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/storage/IIndexCheckpointManager.java
+++ b/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/storage/IIndexCheckpointManager.java
@@ -142,4 +142,12 @@
      * @throws HyracksDataException
      */
     void setLastComponentId(long componentId) throws HyracksDataException;
+
+    /**
+     * Indicates that the index has at least one valid checkpoint
+     *
+     * @return true if the index has at least one valid checkpoint. Otherwise false
+     * @throws HyracksDataException
+     */
+    boolean isValidIndex() throws HyracksDataException;
 }
diff --git a/asterixdb/asterix-replication/src/main/java/org/apache/asterix/replication/logging/RemoteLogsNotifier.java b/asterixdb/asterix-replication/src/main/java/org/apache/asterix/replication/logging/RemoteLogsNotifier.java
index 80bb3c8..42a3c0b 100644
--- a/asterixdb/asterix-replication/src/main/java/org/apache/asterix/replication/logging/RemoteLogsNotifier.java
+++ b/asterixdb/asterix-replication/src/main/java/org/apache/asterix/replication/logging/RemoteLogsNotifier.java
@@ -96,7 +96,9 @@
         for (DatasetResourceReference replicaIndexRef : replicaIndexesRef) {
             final IIndexCheckpointManager indexCheckpointManager = indexCheckpointManagerProvider.get(replicaIndexRef);
             synchronized (indexCheckpointManager) {
-                indexCheckpointManager.masterFlush(remoteLogMapping.getMasterLsn(), remoteLogMapping.getLSN());
+                if (indexCheckpointManager.isValidIndex()) {
+                    indexCheckpointManager.masterFlush(remoteLogMapping.getMasterLsn(), remoteLogMapping.getLSN());
+                }
             }
         }
     }