com.couchbase.lite.CouchbaseLiteException: Conflicts not allowed and there is already an existing doc with id: 4cd9f17d-f28f-48c9-8866-eec3a9cabe35

115 views
Skip to first unread message

peng liu

unread,
Nov 6, 2014, 8:24:35 PM11/6/14
to mobile-c...@googlegroups.com
Hi.I use couchbase on android.
But some times when i  update my doc .it will crash.
11-07 09:19:51.440    9487-9562/com.eusoft.recite.fr W/System.err﹕ com.couchbase.lite.CouchbaseLiteException: Conflicts not allowed and there is already an existing doc with id: 4cd9f17d-f28f-48c9-8866-eec3a9cabe35
11-07 09:19:51.440    9487-9562/com.eusoft.recite.fr W/System.err﹕ at com.couchbase.lite.Database.putRevision(Database.java:3480)
11-07 09:19:51.440    9487-9562/com.eusoft.recite.fr W/System.err﹕ at com.couchbase.lite.Database.putRevision(Database.java:3415)
11-07 09:19:51.440    9487-9562/com.eusoft.recite.fr W/System.err﹕ at com.couchbase.lite.Document.putProperties(Document.java:415)
11-07 09:19:51.440    9487-9562/com.eusoft.recite.fr W/System.err﹕ at com.couchbase.lite.Document.putProperties(Document.java:250)
11-07 09:19:51.440    9487-9562/com.eusoft.recite.fr W/System.err﹕ at com.eusoft.recite.support.entities.AbstractDocument.save(AbstractDocument.java:58)
11-07 09:19:51.440    9487-9562/com.eusoft.recite.fr W/System.err﹕ at com.eusoft.recite.support.entities.AbstractDocument.save(AbstractDocument.java:44)
11-07 09:19:51.440    9487-9562/com.eusoft.recite.fr W/System.err﹕ at com.eusoft.recite.support.ReciteSupportController.updateCardReviewInCouchBase(ReciteSupportController.java:417)
11-07 09:19:51.440    9487-9562/com.eusoft.recite.fr W/System.err﹕ at com.eusoft.recite.support.ReciteSupportController.answerCard(ReciteSupportController.java:815)
11-07 09:19:51.440    9487-9562/com.eusoft.recite.fr W/System.err﹕ at com.eusoft.recite.activity.recite.ReciteActivity$5.run(ReciteActivity.java:170)
11-07 09:19:51.440    9487-9562/com.eusoft.recite.fr W/System.err﹕ at java.lang.Thread.run(Thread.java:841)

and how to fix it ?
but i have try to clean the document cache,it will crash again.
 Database db = DBController.getInstance().getCouchDatabase();
            if (db != null) {
                try {
                    entity.save(db);
                } catch (CouchbaseLiteException e) {
                    db.clearDocumentCache();
                    entity.save(db);
                }
            }

Traun Leyden

unread,
Nov 6, 2014, 8:36:18 PM11/6/14
to mobile-c...@googlegroups.com
It's preventing you from clobbering a later revision that was added.  This can happen if you have the following situation:

* Show user rev1 of document in UI
* Couchabse lite sync's rev2 of doc in background
* You try to save user's changes, based off rev1 (which is now stale)
* Couchbase Lite throws that error, since you passed in rev1 as the previous revision, but rev1 is no longer the latest revision it knows about.

Does that sound like what's happening in your case?

If you debug it, you should see that you are trying to save a revision based on a stale previous revision.  If not, it might be a bug in Couchbase Lite worth looking into.




--
You received this message because you are subscribed to the Google Groups "Couchbase Mobile" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mobile-couchba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mobile-couchbase/a7cb8114-084d-4faa-b9cf-9191a7a7f3d8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

peng liu

unread,
Nov 6, 2014, 8:42:46 PM11/6/14
to mobile-c...@googlegroups.com
I think problem is  case by update same document  twice ? and at second times ,the first is not really update in couchbase ,so when i try update again ,it will crash ????

在 2014年11月7日星期五UTC+8上午9时24分35秒,peng liu写道:

Traun Leyden

unread,
Nov 6, 2014, 8:45:06 PM11/6/14
to mobile-c...@googlegroups.com
Can you produce some standalone code that reproduces the problem?



--
You received this message because you are subscribed to the Google Groups "Couchbase Mobile" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mobile-couchba...@googlegroups.com.

peng liu

unread,
Nov 6, 2014, 8:51:23 PM11/6/14
to mobile-c...@googlegroups.com
11-07 09:49:07.730  10763-10763/com.eusoft.recite.fr E/TAG﹕ word: acquisition
11-07 09:49:56.360  10763-10827/com.eusoft.recite.fr I/CBLite﹕ Thread-2580 Begin transaction (level 1)
11-07 09:49:56.400  10763-10827/com.eusoft.recite.fr I/CBLite﹕ Thread-2580 Committing transaction (level 1)
11-07 09:49:56.490  10763-10827/com.eusoft.recite.fr E/TAG﹕ updateCardReviewInCouchBase: f23e2184-80b1-403b-9e25-8724a55bcb8c
11-07 09:49:56.490  10763-10827/com.eusoft.recite.fr E/TAG﹕ onBeforeSave:properties:{lastEaseFactor=1.3, status=0, lastDueTime=1415324996362, bookId=100, type=Card, dueTime=1415325596362, id=186643, _rev=3-10ea71e7c80967564cf60b8374d2ab92, easeFactor=1.3, unit=100_1, level=0, hide=0, _id=f23e2184-80b1-403b-9e25-8724a55bcb8c, delete=0}
11-07 09:49:56.500  10763-10827/com.eusoft.recite.fr I/CBLite﹕ Thread-2580 Begin transaction (level 1)
11-07 09:49:56.510  10763-10827/com.eusoft.recite.fr I/CBLite﹕ Thread-2580 Committing transaction (level 1)
11-07 09:49:56.560  10763-10827/com.eusoft.recite.fr E/TAG﹕ onAfterSave:properties:{lastEaseFactor=1.3, lastDueTime=1415324996362, status=0, bookId=100, type=Card, _rev=4-3dfd31088dc0b008128b6a52dc23a296, id=186643, dueTime=1415325596362, unit=100_1, easeFactor=1.3, level=0, _id=f23e2184-80b1-403b-9e25-8724a55bcb8c, hide=0, delete=0}
11-07 09:49:56.580  10763-10763/com.eusoft.recite.fr E/TAG﹕ worker total times : 229
11-07 09:49:56.650  10763-10763/com.eusoft.recite.fr D/dalvikvm﹕ GC_FOR_ALLOC freed 2312K, 15% free 15375K/18032K, paused 34ms, total 35ms
11-07 09:49:56.750  10763-10763/com.eusoft.recite.fr D/dalvikvm﹕ GC_FOR_ALLOC freed 1297K, 12% free 15909K/18032K, paused 31ms, total 31ms
11-07 09:50:04.080  10763-10763/com.eusoft.recite.fr E/TAG﹕ word: acquisition
11-07 09:50:07.150  10763-10837/com.eusoft.recite.fr I/CBLite﹕ Thread-2581 Begin transaction (level 1)
11-07 09:50:07.170  10763-10837/com.eusoft.recite.fr I/CBLite﹕ Thread-2581 Committing transaction (level 1)
11-07 09:50:07.230  10763-10837/com.eusoft.recite.fr E/TAG﹕ updateCardReviewInCouchBase: f23e2184-80b1-403b-9e25-8724a55bcb8c
11-07 09:50:07.230  10763-10837/com.eusoft.recite.fr E/TAG﹕ onBeforeSave:properties:{lastEaseFactor=1.3, status=0, lastDueTime=1415325007158, bookId=100, type=Card, dueTime=1415325607158, id=186643, _rev=3-10ea71e7c80967564cf60b8374d2ab92, easeFactor=1.3, unit=100_1, level=0, hide=0, _id=f23e2184-80b1-403b-9e25-8724a55bcb8c, delete=0}
11-07 09:50:07.240  10763-10837/com.eusoft.recite.fr I/CBLite﹕ Thread-2581 Begin transaction (level 1)
11-07 09:50:07.260  10763-10837/com.eusoft.recite.fr I/CBLite﹕ Thread-2581 CANCEL transaction (level 1)
11-07 09:50:07.260  10763-10837/com.eusoft.recite.fr I/CBLite﹕ Thread-2581 Begin transaction (level 1)
11-07 09:50:07.280  10763-10837/com.eusoft.recite.fr I/CBLite﹕ Thread-2581 CANCEL transaction (level 1)
11-07 09:50:07.280  10763-10837/com.eusoft.recite.fr W/System.err﹕ com.couchbase.lite.CouchbaseLiteException: Conflicts not allowed and there is already an existing doc with id: f23e2184-80b1-403b-9e25-8724a55bcb8c
11-07 09:50:07.280  10763-10837/com.eusoft.recite.fr W/System.err﹕ at com.couchbase.lite.Database.putRevision(Database.java:3480)
11-07 09:50:07.280  10763-10837/com.eusoft.recite.fr W/System.err﹕ at com.couchbase.lite.Database.putRevision(Database.java:3415)
11-07 09:50:07.280  10763-10837/com.eusoft.recite.fr W/System.err﹕ at com.couchbase.lite.Document.putProperties(Document.java:415)
11-07 09:50:07.280  10763-10837/com.eusoft.recite.fr W/System.err﹕ at com.couchbase.lite.Document.putProperties(Document.java:250)
11-07 09:50:07.280  10763-10837/com.eusoft.recite.fr W/System.err﹕ at com.eusoft.recite.support.entities.AbstractDocument.save(AbstractDocument.java:55)
11-07 09:50:07.280  10763-10837/com.eusoft.recite.fr W/System.err﹕ at com.eusoft.recite.support.entities.AbstractDocument.save(AbstractDocument.java:43)
11-07 09:50:07.280  10763-10837/com.eusoft.recite.fr W/System.err﹕ at com.eusoft.recite.support.ReciteSupportController.updateCardReviewInCouchBase(ReciteSupportController.java:430)
11-07 09:50:07.280  10763-10837/com.eusoft.recite.fr W/System.err﹕ at com.eusoft.recite.support.ReciteSupportController.answerCard(ReciteSupportController.java:828)
11-07 09:50:07.280  10763-10837/com.eusoft.recite.fr W/System.err﹕ at com.eusoft.recite.activity.recite.ReciteActivity$5.run(ReciteActivity.java:170)
11-07 09:50:07.280  10763-10837/com.eusoft.recite.fr W/System.err﹕ at java.lang.Thread.run(Thread.java:841)
11-07 09:50:07.300  10763-10763/com.eusoft.recite.fr E/TAG﹕ worker total times : 151
11-07 09:50:07.390  10763-10763/com.eusoft.recite.fr D/dalvikvm﹕ GC_FOR_ALLOC freed 2942K, 19% free 15162K/18644K, paused 29ms, total 34ms

在 2014年11月7日星期五UTC+8上午9时24分35秒,peng liu写道:

peng liu

unread,
Nov 6, 2014, 8:57:23 PM11/6/14
to mobile-c...@googlegroups.com
Yes.you got it. you can see my log at my last post comment." updateCardReviewInCouchBase: f23e2184-80b1-403b-9e25-8724a55bcb8c" .
i found that ,i have try update same document id ,and then crash .
so how to fix it ???
i really need update the document .
my app like a card game.so the card is random.and then the card will update any time .
在 2014年11月7日星期五UTC+8上午9时36分18秒,Traun Leyden写道:

peng liu

unread,
Nov 6, 2014, 9:04:48 PM11/6/14
to mobile-c...@googlegroups.com
My some code here:
  public static void updateCardReviewInCouchBase(CardReviewInfoDocument entity) {
        try {
            Database db = DBController.getInstance().getCouchDatabase();
            if (db != null) {
                try {
                    Log.e("TAG", "updateCardReviewInCouchBase: " + entity.getId());
                    entity.save(db, new AbstractDocument.OnDocumentPersistenceListener() {
                        @Override
                        public void onBeforeSave(Map<String, Object> properties) {
                            Log.e("TAG", "onBeforeSave:properties:" + properties.toString());
                        }

                        @Override
                        public void onAfterSave(Document document) {
                            Log.e("TAG", "onAfterSave:properties:" + document.getProperties().toString());
                        }
                    });
                } catch (CouchbaseLiteException e) {
                    db.clearDocumentCache();
                    entity.save(db);
                }
            }
        } catch (CouchbaseLiteException e) {
            e.printStackTrace();
        }
    }

update method:
     public final void save(Database database, OnDocumentPersistenceListener callback) throws CouchbaseLiteException {
        if (callback != null) {
            callback.onBeforeSave(mProperties);
        }
        // Create document if required
        if (mDocument == null) {
            mDocument = database.createDocument();
        }
        // com.couchbase.lite.CouchbaseLiteException: Conflicts not allowed and there is already an existing doc with id: 1180a204-bddd-4ea8-9070-5b24fd17f2de
        mDocument.putProperties(mProperties);

        if (callback != null) {
            callback.onAfterSave(mDocument);
        }
    }

在 2014年11月7日星期五UTC+8上午9时45分06秒,Traun Leyden写道:

peng liu

unread,
Nov 6, 2014, 9:26:53 PM11/6/14
to mobile-c...@googlegroups.com
I think  if i save  (mDocument.putProperties(mProperties)) error. at this time  i can try call the update method ( mDocument.update(new Document.DocumentUpdater())).
and i found the log:
11-07 10:20:28.390  11891-11979/com.eusoft.recite.fr E/TAG﹕ updateCardReviewInCouchBase: 8d9515d3-4a3d-49c2-bbb7-d6f335227db0
11-07 10:20:28.390  11891-11979/com.eusoft.recite.fr I/CBLite﹕ Thread-2598 Begin transaction (level 1)
11-07 10:20:28.410  11891-11979/com.eusoft.recite.fr I/CBLite﹕ Thread-2598 Committing transaction (level 1)
11-07 10:20:31.800  11891-11982/com.eusoft.recite.fr E/TAG﹕ updateCardReviewInCouchBase: 8d9515d3-4a3d-49c2-bbb7-d6f335227db0
11-07 10:20:31.810  11891-11982/com.eusoft.recite.fr I/CBLite﹕ Thread-2599 Begin transaction (level 1)
11-07 10:20:31.820  11891-11982/com.eusoft.recite.fr I/CBLite﹕ Thread-2599 CANCEL transaction (level 1)
11-07 10:20:31.830  11891-11982/com.eusoft.recite.fr I/CBLite﹕ Thread-2599 Begin transaction (level 1)
11-07 10:20:31.840  11891-11982/com.eusoft.recite.fr I/CBLite﹕ Thread-2599 Committing transaction (level 1)

and not  crash again .Am i right ???
Thanks.
在 2014年11月7日星期五UTC+8上午9时45分06秒,Traun Leyden写道:

Traun Leyden

unread,
Nov 7, 2014, 1:51:55 PM11/7/14
to mobile-c...@googlegroups.com
This isn't "standalone" code -- it is referencing code which is not included: CardReviewInfoDocument


Reply all
Reply to author
Forward
0 new messages