Using different versions of serializable objects

classic Classic list List threaded Threaded
6 messages Options
Surkov.Aleksandr Surkov.Aleksandr
Reply | Threaded
Open this post in threaded view
|

Using different versions of serializable objects

Hi igniters!

We use third party classes and store them objects in key-value cache.
This class implements the Serializable interface and defines the readObject
and writeObject methods.

After we decided to switch to a new version of the class and tried to read
from the cache, we received an error:

Exception in thread "main" javax.cache.CacheException: class
org.apache.ignite.IgniteCheckedException: Failed to unmarshal object with
optimized marshaller
                at
org.apache.ignite.internal.processors.cache.GridCacheUtils.convertToCacheException(GridCacheUtils.java:1317)
                at
org.apache.ignite.internal.processors.cache.IgniteCacheProxyImpl.cacheException(IgniteCacheProxyImpl.java:2066)
                at
org.apache.ignite.internal.processors.cache.IgniteCacheProxyImpl.get(IgniteCacheProxyImpl.java:1093)
                at
org.apache.ignite.internal.processors.cache.GatewayProtectedCacheProxy.get(GatewayProtectedCacheProxy.java:676)
                at
com.client.SerializableTest.main(SerializableTest.java:27)
Caused by: class org.apache.ignite.IgniteCheckedException: Failed to
unmarshal object with optimized marshaller
                at
org.apache.ignite.internal.util.IgniteUtils.cast(IgniteUtils.java:7510)
                at
org.apache.ignite.internal.util.future.GridFutureAdapter.resolve(GridFutureAdapter.java:260)
                at
org.apache.ignite.internal.util.future.GridFutureAdapter.get0(GridFutureAdapter.java:191)
                at
org.apache.ignite.internal.util.future.GridFutureAdapter.get(GridFutureAdapter.java:141)
                at
org.apache.ignite.internal.processors.cache.GridCacheAdapter.get(GridCacheAdapter.java:4972)
                at
org.apache.ignite.internal.processors.cache.GridCacheAdapter.repairableGet(GridCacheAdapter.java:4931)
                at
org.apache.ignite.internal.processors.cache.GridCacheAdapter.get(GridCacheAdapter.java:1486)
                at
org.apache.ignite.internal.processors.cache.IgniteCacheProxyImpl.get(IgniteCacheProxyImpl.java:1090)
                ... 2 more
Caused by: class org.apache.ignite.binary.BinaryObjectException: Failed to
unmarshal object with optimized marshaller
                at
org.apache.ignite.internal.binary.BinaryUtils.doReadOptimized(BinaryUtils.java:1785)
                at
org.apache.ignite.internal.binary.BinaryUtils.unmarshal(BinaryUtils.java:1991)
                at
org.apache.ignite.internal.binary.BinaryUtils.unmarshal(BinaryUtils.java:1816)
                at
org.apache.ignite.internal.binary.BinaryUtils.unmarshal(BinaryUtils.java:1807)
                at
org.apache.ignite.internal.binary.GridBinaryMarshaller.unmarshal(GridBinaryMarshaller.java:268)
                at
org.apache.ignite.internal.processors.cache.binary.CacheObjectBinaryProcessorImpl.unmarshal(CacheObjectBinaryProcessorImpl.java:1100)
                at
org.apache.ignite.internal.processors.cache.CacheObjectImpl.value(CacheObjectImpl.java:89)
                at
org.apache.ignite.internal.processors.cache.CacheObjectUtils.unwrapBinary(CacheObjectUtils.java:176)
                at
org.apache.ignite.internal.processors.cache.CacheObjectUtils.unwrapBinaryIfNeeded(CacheObjectUtils.java:67)
                at
org.apache.ignite.internal.processors.cache.CacheObjectContext.unwrapBinaryIfNeeded(CacheObjectContext.java:136)
                at
org.apache.ignite.internal.processors.cache.GridCacheContext.unwrapBinaryIfNeeded(GridCacheContext.java:1808)
                at
org.apache.ignite.internal.processors.cache.GridCacheContext.unwrapBinaryIfNeeded(GridCacheContext.java:1796)
                at
org.apache.ignite.internal.processors.cache.distributed.dht.GridPartitionedSingleGetFuture.setResult(GridPartitionedSingleGetFuture.java:747)
                at
org.apache.ignite.internal.processors.cache.distributed.dht.GridPartitionedSingleGetFuture.onResult(GridPartitionedSingleGetFuture.java:624)
                at
org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtCacheAdapter.processNearSingleGetResponse(GridDhtCacheAdapter.java:374)
                at
org.apache.ignite.internal.processors.cache.distributed.dht.atomic.GridDhtAtomicCache.access$1400(GridDhtAtomicCache.java:141)
                at
org.apache.ignite.internal.processors.cache.distributed.dht.atomic.GridDhtAtomicCache$15.apply(GridDhtAtomicCache.java:429)
                at
org.apache.ignite.internal.processors.cache.distributed.dht.atomic.GridDhtAtomicCache$15.apply(GridDhtAtomicCache.java:424)
                at
org.apache.ignite.internal.processors.cache.GridCacheIoManager.processMessage(GridCacheIoManager.java:1142)
                at
org.apache.ignite.internal.processors.cache.GridCacheIoManager.onMessage0(GridCacheIoManager.java:591)
                at
org.apache.ignite.internal.processors.cache.GridCacheIoManager.handleMessage(GridCacheIoManager.java:392)
                at
org.apache.ignite.internal.processors.cache.GridCacheIoManager.handleMessage(GridCacheIoManager.java:318)
                at
org.apache.ignite.internal.processors.cache.GridCacheIoManager.access$100(GridCacheIoManager.java:109)
                at
org.apache.ignite.internal.processors.cache.GridCacheIoManager$1.onMessage(GridCacheIoManager.java:308)
                at
org.apache.ignite.internal.managers.communication.GridIoManager.invokeListener(GridIoManager.java:1847)
                at
org.apache.ignite.internal.managers.communication.GridIoManager.processRegularMessage0(GridIoManager.java:1472)
                at
org.apache.ignite.internal.managers.communication.GridIoManager.access$5200(GridIoManager.java:229)
                at
org.apache.ignite.internal.managers.communication.GridIoManager$9.run(GridIoManager.java:1367)
                at
org.apache.ignite.internal.util.StripedExecutor$Stripe.body(StripedExecutor.java:565)
                at
org.apache.ignite.internal.util.worker.GridWorker.run(GridWorker.java:120)
                at java.lang.Thread.run(Thread.java:748)
Caused by: class org.apache.ignite.IgniteCheckedException: Failed to find
class with given class loader for unmarshalling (make sure same versions of
all classes are available on all nodes or enable peer-class-loading)
[clsLdr=org.apache.ignite.internal.processors.cache.GridCacheDeploymentManager$CacheClassLoader@32b830a9,
cls=Optimized stream class checksum mismatch (is same version of marshalled
class present on all nodes?) [expected=2, actual=1, cls=class
com.client.SerializableTest$ThirdPartyObj]]
                at
org.apache.ignite.internal.marshaller.optimized.OptimizedMarshaller.unmarshal0(OptimizedMarshaller.java:232)
                at
org.apache.ignite.marshaller.AbstractNodeNameAwareMarshaller.unmarshal(AbstractNodeNameAwareMarshaller.java:93)
                at
org.apache.ignite.internal.binary.BinaryUtils.doReadOptimized(BinaryUtils.java:1782)
                ... 30 more
Caused by: java.lang.ClassNotFoundException: Optimized stream class checksum
mismatch (is same version of marshalled class present on all nodes?)
[expected=2, actual=1, cls=class com.client.SerializableTest$ThirdPartyObj]
                at
org.apache.ignite.internal.marshaller.optimized.OptimizedClassDescriptor.verifyChecksum(OptimizedClassDescriptor.java:969)
                at
org.apache.ignite.internal.marshaller.optimized.OptimizedClassDescriptor.read(OptimizedClassDescriptor.java:951)
                at
org.apache.ignite.internal.marshaller.optimized.OptimizedObjectInputStream.readObject0(OptimizedObjectInputStream.java:346)
                at
org.apache.ignite.internal.marshaller.optimized.OptimizedObjectInputStream.readObjectOverride(OptimizedObjectInputStream.java:198)
                at
java.io.ObjectInputStream.readObject(ObjectInputStream.java:425)
                at
org.apache.ignite.internal.marshaller.optimized.OptimizedMarshaller.unmarshal0(OptimizedMarshaller.java:227)
                ... 32 more


A small reproducer of this situation:

public class SerializableTest {

    public static void main(String[] args) {

        try (IgniteEx client = (IgniteEx)
Ignition.start(getWithSslConfig())) {

            IgniteCache<String, ThirdPartyObj> cache =
client.getOrCreateCache("test");
            // Should be commented out after the first run of the main
method
            cache.put("key", new ThirdPartyObj("Timon"));

            System.out.println(cache.get("key"));

        } catch (IgniteCheckedException e) {
            e.printStackTrace();
        }
    }

    public static class ThirdPartyObj implements Serializable {
// Must be changed after the first run of the main method
        private static final long serialVersionUID = 1L;
        private String name;

        public ThirdPartyObj(String name) {
            this.name = name;
        }

        private void writeObject(ObjectOutputStream outputStream) throws
IOException {
            outputStream.defaultWriteObject();

            outputStream.writeObject(this.name);
        }

        private void readObject(ObjectInputStream inputStream) throws
IOException, ClassNotFoundException {
            inputStream.defaultReadObject();

            this.name = (String) inputStream.readObject();
        }

        @Override
        public String toString() {
            return "ThirdPartyObj{" +
                    "name='" + name + '\'' +
                    '}';
        }
    }
}


Is it possible to use different versions of objects?



--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/
ilya.kasnacheev ilya.kasnacheev
Reply | Threaded
Open this post in threaded view
|

Re: Using different versions of serializable objects

Hello!

Does this still happen if you get rid of Serializable, readObject, writeObject?

Regards,
--
Ilya Kasnacheev


ср, 2 дек. 2020 г. в 09:58, Surkov.Aleksandr <[hidden email]>:
Hi igniters!

We use third party classes and store them objects in key-value cache.
This class implements the Serializable interface and defines the readObject
and writeObject methods.

After we decided to switch to a new version of the class and tried to read
from the cache, we received an error:

Exception in thread "main" javax.cache.CacheException: class
org.apache.ignite.IgniteCheckedException: Failed to unmarshal object with
optimized marshaller
                at
org.apache.ignite.internal.processors.cache.GridCacheUtils.convertToCacheException(GridCacheUtils.java:1317)
                at
org.apache.ignite.internal.processors.cache.IgniteCacheProxyImpl.cacheException(IgniteCacheProxyImpl.java:2066)
                at
org.apache.ignite.internal.processors.cache.IgniteCacheProxyImpl.get(IgniteCacheProxyImpl.java:1093)
                at
org.apache.ignite.internal.processors.cache.GatewayProtectedCacheProxy.get(GatewayProtectedCacheProxy.java:676)
                at
com.client.SerializableTest.main(SerializableTest.java:27)
Caused by: class org.apache.ignite.IgniteCheckedException: Failed to
unmarshal object with optimized marshaller
                at
org.apache.ignite.internal.util.IgniteUtils.cast(IgniteUtils.java:7510)
                at
org.apache.ignite.internal.util.future.GridFutureAdapter.resolve(GridFutureAdapter.java:260)
                at
org.apache.ignite.internal.util.future.GridFutureAdapter.get0(GridFutureAdapter.java:191)
                at
org.apache.ignite.internal.util.future.GridFutureAdapter.get(GridFutureAdapter.java:141)
                at
org.apache.ignite.internal.processors.cache.GridCacheAdapter.get(GridCacheAdapter.java:4972)
                at
org.apache.ignite.internal.processors.cache.GridCacheAdapter.repairableGet(GridCacheAdapter.java:4931)
                at
org.apache.ignite.internal.processors.cache.GridCacheAdapter.get(GridCacheAdapter.java:1486)
                at
org.apache.ignite.internal.processors.cache.IgniteCacheProxyImpl.get(IgniteCacheProxyImpl.java:1090)
                ... 2 more
Caused by: class org.apache.ignite.binary.BinaryObjectException: Failed to
unmarshal object with optimized marshaller
                at
org.apache.ignite.internal.binary.BinaryUtils.doReadOptimized(BinaryUtils.java:1785)
                at
org.apache.ignite.internal.binary.BinaryUtils.unmarshal(BinaryUtils.java:1991)
                at
org.apache.ignite.internal.binary.BinaryUtils.unmarshal(BinaryUtils.java:1816)
                at
org.apache.ignite.internal.binary.BinaryUtils.unmarshal(BinaryUtils.java:1807)
                at
org.apache.ignite.internal.binary.GridBinaryMarshaller.unmarshal(GridBinaryMarshaller.java:268)
                at
org.apache.ignite.internal.processors.cache.binary.CacheObjectBinaryProcessorImpl.unmarshal(CacheObjectBinaryProcessorImpl.java:1100)
                at
org.apache.ignite.internal.processors.cache.CacheObjectImpl.value(CacheObjectImpl.java:89)
                at
org.apache.ignite.internal.processors.cache.CacheObjectUtils.unwrapBinary(CacheObjectUtils.java:176)
                at
org.apache.ignite.internal.processors.cache.CacheObjectUtils.unwrapBinaryIfNeeded(CacheObjectUtils.java:67)
                at
org.apache.ignite.internal.processors.cache.CacheObjectContext.unwrapBinaryIfNeeded(CacheObjectContext.java:136)
                at
org.apache.ignite.internal.processors.cache.GridCacheContext.unwrapBinaryIfNeeded(GridCacheContext.java:1808)
                at
org.apache.ignite.internal.processors.cache.GridCacheContext.unwrapBinaryIfNeeded(GridCacheContext.java:1796)
                at
org.apache.ignite.internal.processors.cache.distributed.dht.GridPartitionedSingleGetFuture.setResult(GridPartitionedSingleGetFuture.java:747)
                at
org.apache.ignite.internal.processors.cache.distributed.dht.GridPartitionedSingleGetFuture.onResult(GridPartitionedSingleGetFuture.java:624)
                at
org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtCacheAdapter.processNearSingleGetResponse(GridDhtCacheAdapter.java:374)
                at
org.apache.ignite.internal.processors.cache.distributed.dht.atomic.GridDhtAtomicCache.access$1400(GridDhtAtomicCache.java:141)
                at
org.apache.ignite.internal.processors.cache.distributed.dht.atomic.GridDhtAtomicCache$15.apply(GridDhtAtomicCache.java:429)
                at
org.apache.ignite.internal.processors.cache.distributed.dht.atomic.GridDhtAtomicCache$15.apply(GridDhtAtomicCache.java:424)
                at
org.apache.ignite.internal.processors.cache.GridCacheIoManager.processMessage(GridCacheIoManager.java:1142)
                at
org.apache.ignite.internal.processors.cache.GridCacheIoManager.onMessage0(GridCacheIoManager.java:591)
                at
org.apache.ignite.internal.processors.cache.GridCacheIoManager.handleMessage(GridCacheIoManager.java:392)
                at
org.apache.ignite.internal.processors.cache.GridCacheIoManager.handleMessage(GridCacheIoManager.java:318)
                at
org.apache.ignite.internal.processors.cache.GridCacheIoManager.access$100(GridCacheIoManager.java:109)
                at
org.apache.ignite.internal.processors.cache.GridCacheIoManager$1.onMessage(GridCacheIoManager.java:308)
                at
org.apache.ignite.internal.managers.communication.GridIoManager.invokeListener(GridIoManager.java:1847)
                at
org.apache.ignite.internal.managers.communication.GridIoManager.processRegularMessage0(GridIoManager.java:1472)
                at
org.apache.ignite.internal.managers.communication.GridIoManager.access$5200(GridIoManager.java:229)
                at
org.apache.ignite.internal.managers.communication.GridIoManager$9.run(GridIoManager.java:1367)
                at
org.apache.ignite.internal.util.StripedExecutor$Stripe.body(StripedExecutor.java:565)
                at
org.apache.ignite.internal.util.worker.GridWorker.run(GridWorker.java:120)
                at java.lang.Thread.run(Thread.java:748)
Caused by: class org.apache.ignite.IgniteCheckedException: Failed to find
class with given class loader for unmarshalling (make sure same versions of
all classes are available on all nodes or enable peer-class-loading)
[clsLdr=org.apache.ignite.internal.processors.cache.GridCacheDeploymentManager$CacheClassLoader@32b830a9,
cls=Optimized stream class checksum mismatch (is same version of marshalled
class present on all nodes?) [expected=2, actual=1, cls=class
com.client.SerializableTest$ThirdPartyObj]]
                at
org.apache.ignite.internal.marshaller.optimized.OptimizedMarshaller.unmarshal0(OptimizedMarshaller.java:232)
                at
org.apache.ignite.marshaller.AbstractNodeNameAwareMarshaller.unmarshal(AbstractNodeNameAwareMarshaller.java:93)
                at
org.apache.ignite.internal.binary.BinaryUtils.doReadOptimized(BinaryUtils.java:1782)
                ... 30 more
Caused by: java.lang.ClassNotFoundException: Optimized stream class checksum
mismatch (is same version of marshalled class present on all nodes?)
[expected=2, actual=1, cls=class com.client.SerializableTest$ThirdPartyObj]
                at
org.apache.ignite.internal.marshaller.optimized.OptimizedClassDescriptor.verifyChecksum(OptimizedClassDescriptor.java:969)
                at
org.apache.ignite.internal.marshaller.optimized.OptimizedClassDescriptor.read(OptimizedClassDescriptor.java:951)
                at
org.apache.ignite.internal.marshaller.optimized.OptimizedObjectInputStream.readObject0(OptimizedObjectInputStream.java:346)
                at
org.apache.ignite.internal.marshaller.optimized.OptimizedObjectInputStream.readObjectOverride(OptimizedObjectInputStream.java:198)
                at
java.io.ObjectInputStream.readObject(ObjectInputStream.java:425)
                at
org.apache.ignite.internal.marshaller.optimized.OptimizedMarshaller.unmarshal0(OptimizedMarshaller.java:227)
                ... 32 more


A small reproducer of this situation:

public class SerializableTest {

    public static void main(String[] args) {

        try (IgniteEx client = (IgniteEx)
Ignition.start(getWithSslConfig())) {

            IgniteCache<String, ThirdPartyObj> cache =
client.getOrCreateCache("test");
            // Should be commented out after the first run of the main
method
            cache.put("key", new ThirdPartyObj("Timon"));

            System.out.println(cache.get("key"));

        } catch (IgniteCheckedException e) {
            e.printStackTrace();
        }
    }

    public static class ThirdPartyObj implements Serializable {
// Must be changed after the first run of the main method
        private static final long serialVersionUID = 1L;
        private String name;

        public ThirdPartyObj(String name) {
            this.name = name;
        }

        private void writeObject(ObjectOutputStream outputStream) throws
IOException {
            outputStream.defaultWriteObject();

            outputStream.writeObject(this.name);
        }

        private void readObject(ObjectInputStream inputStream) throws
IOException, ClassNotFoundException {
            inputStream.defaultReadObject();

            this.name = (String) inputStream.readObject();
        }

        @Override
        public String toString() {
            return "ThirdPartyObj{" +
                    "name='" + name + '\'' +
                    '}';
        }
    }
}


Is it possible to use different versions of objects?



--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/
Surkov.Aleksandr Surkov.Aleksandr
Reply | Threaded
Open this post in threaded view
|

Re: Using different versions of serializable objects

If I delete only methods (leave the interface), then there are no errors.



--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/
ilya.kasnacheev ilya.kasnacheev
Reply | Threaded
Open this post in threaded view
|

Re: Using different versions of serializable objects

Hello!

Does it solve your issue?

Regards,
--
Ilya Kasnacheev


ср, 2 дек. 2020 г. в 16:50, Surkov.Aleksandr <[hidden email]>:
If I delete only methods (leave the interface), then there are no errors.



--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/
Surkov.Aleksandr Surkov.Aleksandr
Reply | Threaded
Open this post in threaded view
|

Re: Using different versions of serializable objects

no, because we use third party classes and cannot change them



--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/
ilya.kasnacheev ilya.kasnacheev
Reply | Threaded
Open this post in threaded view
|

Re: Using different versions of serializable objects

Hello!

You can try specifying BinaryConfiguration where you would supply a BinaryTypeConfiguration for this type name, specifying a custom BinarySerializer. Then you can try supplying BinaryReflectiveSerializer there.


Regards,
--
Ilya Kasnacheev


ср, 2 дек. 2020 г. в 19:00, Surkov.Aleksandr <[hidden email]>:
no, because we use third party classes and cannot change them



--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/