couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Apache Wiki <wikidi...@apache.org>
Subject [Couchdb Wiki] Update of "How to replicate a database" by BrianCandler
Date Wed, 28 Jan 2009 17:11:20 GMT
Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Couchdb Wiki" for change notification.

The following page has been changed by BrianCandler:
http://wiki.apache.org/couchdb/How_to_replicate_a_database

The comment on the change is:
Add sample shell script

------------------------------------------------------------------------------
  {"_id":"doc1","_rev":"923422654","hello":"resolved","_conflicts":["132006080"]}
  }}}
  
+ === Sample shell script ===
+ 
+ Running this script gives an easy way to demonstrate replication behaviour.
+ 
+ {{{
+ #!/bin/sh
+ set -xe
+ 
+ HOST1=http://localhost:5001
+ HOST2=http://localhost:5002
+ LOCAL1=sampledb
+ LOCAL2=sampledb
+ DB1="$HOST1/$LOCAL1"
+ DB2="$HOST2/$LOCAL2"
+ 
+ curl -X DELETE "$DB1"; echo
+ curl -X DELETE "$DB2"; echo
+ curl -X PUT "$DB1"; echo
+ curl -X PUT "$DB2"; echo
+ 
+ resp=`curl -sX PUT -d "{\"hello\":\"world\"}" "${DB1}/doc1"`
+ echo "$resp"; echo
+ rev=`expr "$resp" : '.*"rev":"\([^"]*\)"'`
+ 
+ # Replicate
+ curl -X POST -d "{\"source\":\"$DB1\",\"target\":\"$LOCAL2\"}" "$HOST2/_replicate"; echo
+ curl -s "$DB1/doc1" | grep world
+ curl -s "$DB2/doc1" | grep world
+ 
+ # Now make conflicting changes
+ curl -sX PUT -d "{\"_rev\":\"$rev\",\"hello\":\"fred\"}" "${DB1}/doc1"
+ curl -sX PUT -d "{\"_rev\":\"$rev\",\"hello\":\"jim\"}" "${DB2}/doc1"
+ curl -s "$DB1/doc1" | grep fred
+ curl -s "$DB2/doc1" | grep jim
+ 
+ # Replicate again, A->B. Conflict seen on B side only.
+ curl -X POST -d "{\"source\":\"$DB1\",\"target\":\"$LOCAL2\"}" "$HOST2/_replicate"; echo
+ echo "*** On first DB ***"
+ curl -s "$DB1/doc1?conflicts=true"; echo
+ echo "*** On second DB ***"
+ curl -s "$DB2/doc1?conflicts=true"; echo
+ 
+ # Replicate again, B->A. Identical conflict on both sides.
+ curl -X POST -d "{\"target\":\"$DB1\",\"source\":\"$LOCAL2\"}" "$HOST2/_replicate"; echo
+ echo "*** On first DB ***"
+ curl -s "$DB1/doc1?conflicts=true"; echo
+ echo "*** On second DB ***"
+ curl -s "$DB2/doc1?conflicts=true"; echo
+ }}}
+ 

Mime
View raw message