cloudant / sync-android

A JSON-based document datastore for Android applications
Apache License 2.0
267 stars 90 forks source link

Synchronization error after upgrading server to CouchDB 2.3 #593

Closed jjrodrig closed 5 years ago

jjrodrig commented 5 years ago

Please read these guidelines before opening an issue.

Bug Description

After upgrading server to CouchDB 2.3 the synchronization is failling with the following exception:

1560 15126 W RetriableTask: Received an exception during response stream processing. A retry will be attempted.
01-03 02:31:25.336 31560 15126 W RetriableTask: java.lang.RuntimeException: com.fasterxml.jackson.databind.exc.InvalidFormatException: Cannot deserialize value of type `long` from String "0-g1AAAABXeJzLYWBgYMpgTmEQTM4vTc5ISXIwNDLXMwBCwxyQVCJDUv3___-zEhnwKMpjAZIMDUDqP0RtFgDZJhhE": not a valid Long value
01-03 02:31:25.336 31560 15126 W RetriableTask:  at [Source: (InputStreamReader); line: 1, column: 39] (through reference chain: com.cloudant.sync.internal.mazha.CouchDbInfo["purge_seq"])
01-03 02:31:25.336 31560 15126 W RetriableTask:     at com.cloudant.sync.internal.util.JSONUtils.fromJson(JSONUtils.java:209)
01-03 02:31:25.336 31560 15126 W RetriableTask:     at com.cloudant.sync.internal.mazha.CouchClient$TypeInputStreamProcessor.processStream(CouchClient.java:793)
01-03 02:31:25.336 31560 15126 W RetriableTask:     at com.cloudant.sync.internal.mazha.CouchClient.executeWithRetry(CouchClient.java:215)
01-03 02:31:25.336 31560 15126 W RetriableTask:     at com.cloudant.sync.internal.mazha.CouchClient.executeWithRetry(CouchClient.java:259)
01-03 02:31:25.336 31560 15126 W RetriableTask:     at com.cloudant.sync.internal.mazha.CouchClient.executeToJsonObjectWithRetry(CouchClient.java:244)
01-03 02:31:25.336 31560 15126 W RetriableTask:     at com.cloudant.sync.internal.mazha.CouchClient.executeToJsonObjectWithRetry(CouchClient.java:249)
01-03 02:31:25.336 31560 15126 W RetriableTask:     at com.cloudant.sync.internal.mazha.CouchClient.getDbInfo(CouchClient.java:279)
01-03 02:31:25.336 31560 15126 W RetriableTask:     at com.cloudant.sync.internal.replication.CouchClientWrapper.exists(CouchClientWrapper.java:76)
01-03 02:31:25.336 31560 15126 W RetriableTask:     at com.cloudant.sync.internal.replication.PushStrategy.replicate(PushStrategy.java:201)
01-03 02:31:25.336 31560 15126 W RetriableTask:     at com.cloudant.sync.internal.replication.PushStrategy.run(PushStrategy.java:165)
01-03 02:31:25.336 31560 15126 W RetriableTask:     at java.lang.Thread.run(Thread.java:764)
01-03 02:31:25.336 31560 15126 W RetriableTask: Caused by: com.fasterxml.jackson.databind.exc.InvalidFormatException: Cannot deserialize value of type `long` from String "0-g1AAAABXeJzLYWBgYMpgTmEQTM4vTc5ISXIwNDLXMwBCwxyQVCJDUv3___-zEhnwKMpjAZIMDUDqP0RtFgDZJhhE": not a valid Long value
01-03 02:31:25.336 31560 15126 W RetriableTask:  at [Source: (InputStreamReader); line: 1, column: 39] (through reference chain: com.cloudant.sync.internal.mazha.CouchDbInfo["purge_seq"])
01-03 02:31:25.336 31560 15126 W RetriableTask:     at com.fasterxml.jackson.databind.DeserializationContext.weirdStringException(DeserializationContext.java:1548)
01-03 02:31:25.336 31560 15126 W RetriableTask:     at com.fasterxml.jackson.databind.DeserializationContext.handleWeirdStringValue(DeserializationContext.java:910)
01-03 02:31:25.336 31560 15126 W RetriableTask:     at com.fasterxml.jackson.databind.deser.std.NumberDeserializers$LongDeserializer._parseLong(NumberDeserializers.java:584)
01-03 02:31:25.336 31560 15126 W RetriableTask:     at com.fasterxml.jackson.databind.deser.std.NumberDeserializers$LongDeserializer.deserialize(NumberDeserializers.java:557)
01-03 02:31:25.336 31560 15126 W RetriableTask:     at com.fasterxml.jackson.databind.deser.std.NumberDeserializers$LongDeserializer.deserialize(NumberDeserializers.java:535)
01-03 02:31:25.336 31560 15126 W RetriableTask:     at com.fasterxml.jackson.databind.deser.impl.FieldProperty.deserializeAndSet(FieldProperty.java:136)
01-03 02:31:25.336 31560 15126 W RetriableTask:     at com.fasterxml.jackson.databind.deser.BeanDeserializer.vanillaDeserialize(BeanDeserializer.java:287)
01-03 02:31:25.336 31560 15126 W RetriableTask:     at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:151)
01-03 02:31:25.336 31560 15126 W RetriableTask:     at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:4001)
01-03 02:31:25.336 31560 15126 W RetriableTask:     at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3044)
01-03 02:31:25.336 31560 15126 W RetriableTask:     at com.cloudant.sync.internal.util.JSONUtils.fromJson(JSONUtils.java:207)
01-03 02:31:25.336 31560 15126 W RetriableTask:     ... 10 more

CouchDB 2.3 has changed the purge_seq attribute from long to string which is a breaking change for Cloudant Sync.

Te problem appears when the repplication process checks the existencie of the remote database by requesting the db informaton.

1. Steps to reproduce and the simplest code sample possible to demonstrate the issue

Perform a replication with a CouchDB 2.3 server

2. What you expected to happen

Synchronize without exceptions

3. What actually happened

The shyncronization is stopped

Environment details

CouchDB 2.3 on the server

emlaver commented 5 years ago

Hi @jjrodrig, what version of the sync-android library are you using?

jjrodrig commented 5 years ago

Hi @emlaver, we are using 2.2.0 version of sync-android

emlaver commented 5 years ago

@jjrodrig You said above: "The problem appears when the repplication process checks the existencie of the remote database by requesting the db informaton." Could you please share your code where the exception is raised?

jjrodrig commented 5 years ago

The error appears parsing the response of GET <remote-host>/database We just have a push and pull replication configured.

I 'm testing minor change on sync-android that changes the type of purgeSeq propery from long to String in com.cloudant.sync.internal.mazha.CouchDbInfo

It seems to not break pre-2.3 CouchDB installations, now I'm configuring a CouchDB 2.3 environment for testing.

I can open a PR with this change.

emlaver commented 5 years ago

@jjrodrig I've merged your PR, thanks for your work!