[ASTERIXDB-2162][STO] Ensure backward compatibility of component id

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

Details:
- Ensure the compatibility of component id change on legacy dataset
https://asterix-gerrit.ics.uci.edu/#/c/2125/. We use a default component
id generator, which always return a missing component id for these
datasets.

Change-Id: Ie61103b640c37729d43023b92b1245b8e2f4a264
Reviewed-on: https://asterix-gerrit.ics.uci.edu/2147
Sonar-Qube: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Contrib: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Integration-Tests: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Reviewed-by: Michael Blow <mblow@apache.org>
Reviewed-by: Ian Maxon <imaxon@apache.org>
diff --git a/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/ioopcallbacks/AbstractLSMIndexIOOperationCallbackFactory.java b/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/ioopcallbacks/AbstractLSMIndexIOOperationCallbackFactory.java
index 16447fd..5dff7f4 100644
--- a/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/ioopcallbacks/AbstractLSMIndexIOOperationCallbackFactory.java
+++ b/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/ioopcallbacks/AbstractLSMIndexIOOperationCallbackFactory.java
@@ -19,16 +19,20 @@
 
 package org.apache.asterix.common.ioopcallbacks;
 
+import java.io.ObjectStreamException;
+
 import org.apache.hyracks.api.application.INCServiceContext;
+import org.apache.hyracks.storage.am.lsm.common.api.ILSMComponentId;
 import org.apache.hyracks.storage.am.lsm.common.api.ILSMComponentIdGenerator;
 import org.apache.hyracks.storage.am.lsm.common.api.ILSMComponentIdGeneratorFactory;
 import org.apache.hyracks.storage.am.lsm.common.api.ILSMIOOperationCallbackFactory;
+import org.apache.hyracks.storage.am.lsm.common.impls.LSMComponentId;
 
 public abstract class AbstractLSMIndexIOOperationCallbackFactory implements ILSMIOOperationCallbackFactory {
 
     private static final long serialVersionUID = 1L;
 
-    protected final ILSMComponentIdGeneratorFactory idGeneratorFactory;
+    protected ILSMComponentIdGeneratorFactory idGeneratorFactory;
 
     protected transient INCServiceContext ncCtx;
 
@@ -42,7 +46,30 @@
     }
 
     protected ILSMComponentIdGenerator getComponentIdGenerator() {
-        assert ncCtx != null;
         return idGeneratorFactory.getComponentIdGenerator(ncCtx);
     }
+
+    private void readObjectNoData() throws ObjectStreamException {
+        idGeneratorFactory = new ILSMComponentIdGeneratorFactory() {
+            private static final long serialVersionUID = 1L;
+
+            @Override
+            public ILSMComponentIdGenerator getComponentIdGenerator(INCServiceContext serviceCtx) {
+                // used for backward compatibility
+                // if idGeneratorFactory is not set for legacy lsm indexes, we return a default
+                // component id generator which always generates the missing component id.
+                return new ILSMComponentIdGenerator() {
+                    @Override
+                    public void refresh() {
+                        // No op
+                    }
+
+                    @Override
+                    public ILSMComponentId getId() {
+                        return LSMComponentId.MISSING_COMPONENT_ID;
+                    }
+                };
+            }
+        };
+    }
 }
diff --git a/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-common/src/main/java/org/apache/hyracks/storage/am/lsm/common/impls/AbstractLSMMemoryComponent.java b/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-common/src/main/java/org/apache/hyracks/storage/am/lsm/common/impls/AbstractLSMMemoryComponent.java
index 0378aae..6a186dc 100644
--- a/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-common/src/main/java/org/apache/hyracks/storage/am/lsm/common/impls/AbstractLSMMemoryComponent.java
+++ b/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-common/src/main/java/org/apache/hyracks/storage/am/lsm/common/impls/AbstractLSMMemoryComponent.java
@@ -272,7 +272,8 @@
 
     @Override
     public void resetId(ILSMComponentId componentId) throws HyracksDataException {
-        if (this.componentId != null && this.componentId.compareTo(componentId) != IdCompareResult.LESS_THAN) {
+        if (this.componentId != null && !componentId.missing() // for backward compatibility
+                && this.componentId.compareTo(componentId) != IdCompareResult.LESS_THAN) {
             throw new IllegalStateException(
                     "LSM memory component receives illegal id. Old id " + this.componentId + ", new id " + componentId);
         }
diff --git a/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-common/src/main/java/org/apache/hyracks/storage/am/lsm/common/impls/LSMComponentIdGeneratorFactory.java b/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-common/src/main/java/org/apache/hyracks/storage/am/lsm/common/impls/LSMComponentIdGeneratorFactory.java
index c55ef19..728c90a 100644
--- a/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-common/src/main/java/org/apache/hyracks/storage/am/lsm/common/impls/LSMComponentIdGeneratorFactory.java
+++ b/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-common/src/main/java/org/apache/hyracks/storage/am/lsm/common/impls/LSMComponentIdGeneratorFactory.java
@@ -29,6 +29,8 @@
  */
 public class LSMComponentIdGeneratorFactory implements ILSMComponentIdGeneratorFactory {
 
+    private static final long serialVersionUID = 1L;
+
     @Override
     public ILSMComponentIdGenerator getComponentIdGenerator(INCServiceContext serviceCtx) {
         return new LSMComponentIdGenerator();