GithubHelp home page GithubHelp logo

karthik-couchbase / sg-find-conflict-demo Goto Github PK

View Code? Open in Web Editor NEW

This project forked from fujio-turner/sg-find-conflict-demo

0.0 2.0 0.0 25 KB

A simple conflict resolver for Sync Gateway

License: Apache License 2.0

Python 100.00%

sg-find-conflict-demo's Introduction

sg-find-conflict-demo

A simple conflict resolver for Sync Gateway

Insert into your cron tab put hostname of the SG machine at the end.

* * * * * /usr/bin/python /path/to/sg-find-conflict-demo/find-conflict.py 8.8.8.8

FAQ

Q:How does it resolves conflicts?

A:Sync Gateway uses the CouchDB method of determining which revision of a document in conflict to show.

CouchDB guarantees that each instance that sees the same conflict comes up with the same winning and losing revisions. It does so by running a deterministic algorithm to pick the winner. The application should not rely on the details of this algorithm and must always resolve conflicts. We’ll tell you how it works anyway.

Each revision includes a list of previous revisions. The revision with the longest revision history list becomes the winning revision. If they are the same, the _rev values are compared in ASCII sort order, and the highest wins. So, in our example, 2-de0ea16f8621cbac506d23a0fbbde08a beats 2-7c971bb974251ae8541b8fe045964219.

One advantage of this algorithm is that CouchDB nodes do not have to talk to each other to agree on winning revisions. We already learned that the network is prone to errors and avoiding it for conflict resolution makes CouchDB very robust.

source:http://guide.couchdb.org/draft/conflicts.html

The default shown document will be the "winner" and the script will removing(deleting) the other revisions in conflict.

Q:Can I change the logic to pick a specific winner?

A:Yes, you'll have to change the script to your needs.

Just put in your logic here on line 184 in find-conflicts.py

	def findConflict(self,data_json = []):
		doc_id = data_json["id"]
		winner = data_json["changes"][0]
		losers = data_json["changes"][1:]

Q:How often does it run?

A:Once a minute is a good starting point. Remember it takes time for it to process the _changes feed.

Q:Does it process all the documents in the whole Sync Gateway Database every time it runs?

A: No, it process the whole _changes feed the first it run , but then it creates a checkpoint and process the changes since the last point it processed the _changes feed.

Q:Can I run the conflict finder on multiple Sync gateways?

A: Yes, but make sure they don't run at the exact same time. Example SG 8.8.8.8 every 13 seconds and SG 9.9.9.9 run every 43 seconds. Prime number intervals are a good guide line.

sg-find-conflict-demo's People

Contributors

fujio-turner avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.