Merge branch 'gerrit/neo' into 'gerrit/trinity'

Change-Id: I0f44ce0d7da3a12765f2ce9deed5910e63d733e3
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 290734f..34f0cb1 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
@@ -128,6 +128,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 beb8e07..9777879 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
@@ -140,4 +140,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());
+                }
             }
         }
     }