couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Brian Candler <B.Cand...@pobox.com>
Subject Trouble with replication
Date Wed, 28 Jan 2009 15:30:26 GMT
Something strange is going on with replication, and I don't understand it.

I started writing up replication conflicts for the wiki - see below.

However, when it got to the point where I made conflicting changes on two
servers and then tried to replicate them, it didn't behave how I expected.
After the _replicate, I expected both servers to have identical copies of
the document with _conflicts members. But actually, they were both unchanged
(with their own separate versions), as you can see in the transcript.

So I tried requesting the same replication in futon pointing at 5002:
  Remote http://127.0.0.1:5001/sampledb <=> Local sampledb
  
and nothing further changed. But then I tried doing it backwards in the
same futon instance:
  Local sampledb <=> Remote http://127.0.0.1:5001/
  
After this the two databases _did_ come into sync. But now there doesn't seem
to be any indication of a conflict:

$ curl http://127.0.0.1:5001/sampledb/doc1?revs=true
{"_id":"doc1","_rev":"2741194541","hello":"jim","_revs":["2741194541","183362165"]}
$ curl http://127.0.0.1:5001/sampledb/doc1?revs_info=true
{"_id":"doc1","_rev":"2741194541","hello":"jim","_revs_info":[{"rev":"2741194541","status":"available"},{"rev":"183362165","status":"available"}]}
$ curl http://127.0.0.1:5002/sampledb/doc1?revs=true
{"_id":"doc1","_rev":"2741194541","hello":"jim","_revs":["2741194541","183362165"]}
$ curl http://127.0.0.1:5002/sampledb/doc1?revs_info=true
{"_id":"doc1","_rev":"2741194541","hello":"jim","_revs_info":[{"rev":"2741194541","status":"available"},{"rev":"183362165","status":"available"}]}

Similarly, with futon I can browse to the previous version, but there is no
trace of {"hello":"fred"} anywhere.

So:
- is there something I need to do to view the conflicts?
- is it necessary to do two POSTs, one to replicate from A to B, and
  the other to replicate from B to A ??

This is using:
couchdb - Apache CouchDB 0.9.0a738034-incubating
under Ubuntu Hardy, with erlang 1:12.b.3-dfsg-1ubuntu1 from Intrepid.

All the tests in the test suite passed, including replication.

I have also written and attached a shell script which does this test.
Just point it at two database instances.

Thanks,

Brian.


== Testing replication ==

It's straightforward to set up two test couchdb instances on the same machine. Here is local1.ini:

{{{
; Remember to create the directories:
;   mkdir -p /var/tmp/couchdb1/{data,log}
;
; Start using:
;   couchdb -c /usr/local/etc/couchdb/default.ini -c local1.ini

[couchdb]
database_dir = /var/tmp/couchdb1/data

[log]
file = /var/tmp/couchdb1/log/couch.log

[httpd]
port = 5001
}}}

Similarly local2.ini:

{{{
; Remember to create the directories:
;   mkdir -p /var/tmp/couchdb2/{data,log}
;
; Start using:
;   couchdb -c /usr/local/etc/couchdb/default.ini -c local2.ini

[couchdb]
database_dir = /var/tmp/couchdb2/data

[log]
file = /var/tmp/couchdb2/log/couch.log

[httpd]
port = 5002
}}}

Test they are both running:

{{{
$ curl http://localhost:5001/
{"couchdb":"Welcome","version":"0.9.0a738034-incubating"}
$ curl http://localhost:5002/
{"couchdb":"Welcome","version":"0.9.0a738034-incubating"}
}}}

=== Create and replicate a document ===

{{{
$ curl -X PUT http://localhost:5001/sampledb
{"ok":true}
$ curl -X PUT http://localhost:5002/sampledb
{"ok":true}

$ curl -X PUT -d '{"hello":"world"}' http://localhost:5001/sampledb/doc1
{"ok":true,"id":"doc1","rev":"183362165"}

$ curl -X POST -d '{"source":"http://127.0.0.1:5001/sampledb","target":"sampledb"}' http://localhost:5002/_replicate
{
  "ok":true,
  "session_id":"aa323b1d173b3751e37bef89f0c678c9",
  "source_last_seq":0,
  "history":
  [
    {
      "start_time":"Wed, 28 Jan 2009 14:26:10 GMT",
      "end_time":"Wed, 28 Jan 2009 14:26:10 GMT",
      "start_last_seq":0,
      "end_last_seq":1,
      "missing_checked":1,
      "missing_found":1,
      "docs_read":1,
      "docs_written":1
    }
  ]
}
}}}

''POST response has been reformatted for clarity''

{{{
$ curl http://127.0.0.1:5001/sampledb/doc1
{"_id":"doc1","_rev":"183362165","hello":"world"} 
$ curl http://127.0.0.1:5002/sampledb/doc1
{"_id":"doc1","_rev":"183362165","hello":"world"} 
}}}

=== Create conflicting updates ===

''Note: the updates have to be made on separate databases. Update conflicts can't occur within
a single database; because you provide the original _rev, if someone else has already changed
the document, the second update is rejected.''

{{{
$ curl -X PUT -d '{"_rev":"183362165","hello":"fred"}' http://localhost:5001/sampledb/doc1
{"ok":true,"id":"doc1","rev":"1091171964"}
$ curl -X PUT -d '{"_rev":"183362165","hello":"jim"}' http://localhost:5002/sampledb/doc1
{"ok":true,"id":"doc1","rev":"2741194541"}

$ curl -X POST -d '{"source":"http://127.0.0.1:5001/sampledb","target":"sampledb"}' http://localhost:5002/_replicate
{
  "ok":true,
  "session_id":"e90fd0142ae9bbd986124c12cedbe58c",
  "source_last_seq":0,
  "history":
  [
    {
      "start_time":"Wed, 28 Jan 2009 14:32:08 GMT",
      "end_time":"Wed, 28 Jan 2009 14:32:08 GMT",
      "start_last_seq":0,
      "end_last_seq":2,
      "missing_checked":1,
      "missing_found":1,
      "docs_read":1,
      "docs_written":1
    }
  ]
}

$ curl http://127.0.0.1:5001/sampledb/doc1
{"_id":"doc1","_rev":"1091171964","hello":"fred"}
$ curl http://127.0.0.1:5002/sampledb/doc1
{"_id":"doc1","_rev":"2741194541","hello":"jim"}
}}}

... What's gone wrong ??

Mime
View raw message