[NO ISSUE][STO] Skip flush recovery of empty resources

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

Details:
- Before this change, recovery would throw a NullPointerException
  on recovery of a flush operation on a component without
  update logs.
- Since this can happen, we simply check for the case and skip the
  flush.

Change-Id: Ib01d7513f43830109632760860d34ca3dcddeaee
Reviewed-on: https://asterix-gerrit.ics.uci.edu/2844
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Contrib: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Reviewed-by: abdullah alamoudi <bamousaa@gmail.com>
Integration-Tests: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Reviewed-by: Murtadha Hubail <mhubail@apache.org>
diff --git a/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/nc/RecoveryManager.java b/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/nc/RecoveryManager.java
index 5e8a5e8..adf9960 100644
--- a/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/nc/RecoveryManager.java
+++ b/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/nc/RecoveryManager.java
@@ -296,7 +296,7 @@
                 ((INcApplicationContext) (serviceCtx.getApplicationContext())).getIndexCheckpointManagerProvider();
 
         Map<Long, LocalResource> resourcesMap = localResourceRepository.loadAndGetAllResources();
-        Map<Long, Long> resourceId2MaxLSNMap = new HashMap<>();
+        final Map<Long, Long> resourceId2MaxLSNMap = new HashMap<>();
         TxnEntityId tempKeyTxnEntityId = new TxnEntityId(-1, -1, -1, null, -1, false);
 
         ILogRecord logRecord = null;
@@ -399,19 +399,25 @@
                             // we only need to flush open indexes here (opened by previous update records)
                             // if an index has no ongoing updates, then it's memory component must be empty
                             // and there is nothing to flush
-                            for (IndexInfo iInfo : dsInfo.getIndexes().values()) {
+                            for (final IndexInfo iInfo : dsInfo.getIndexes().values()) {
                                 if (iInfo.isOpen() && iInfo.getPartition() == partition) {
-                                    maxDiskLastLsn = resourceId2MaxLSNMap.get(iInfo.getResourceId());
-                                    index = iInfo.getIndex();
-                                    if (logRecord.getLSN() > maxDiskLastLsn
-                                            && !index.isCurrentMutableComponentEmpty()) {
-                                        // schedule flush
-                                        redoFlush(index, logRecord);
-                                        redoCount++;
+                                    Long maxLsnBeforeFlush = resourceId2MaxLSNMap.get(iInfo.getResourceId());
+                                    if (maxLsnBeforeFlush != null) {
+                                        // If there was at least one update to the resource.
+                                        // IMPORTANT: Don't remove the check above
+                                        // This check is to support indexes without transaction logs
+                                        maxDiskLastLsn = maxLsnBeforeFlush;
+                                        index = iInfo.getIndex();
+                                        if (logRecord.getLSN() > maxDiskLastLsn
+                                                && !index.isCurrentMutableComponentEmpty()) {
+                                            // schedule flush
+                                            redoFlush(index, logRecord);
+                                            redoCount++;
+                                        } else {
+                                            // TODO: update checkpoint file?
+                                        }
                                     } else {
-                                        // otherwise, do nothing since this component had no records when flush was
-                                        // scheduled.. TODO: update checkpoint file? and do the
-                                        // lsn checks from the checkpoint file
+                                        // TODO: update checkpoint file?
                                     }
                                 }
                             }