Apache CouchDB
Course: Advanced Databases
Group 5: Trinh Phuc Tho, Vo Quoc Khanh, Hoang Trung Hieu
1
What to expect?
 Technical Overview
 Consistency Model
 Live Demo
2
Technical Overview
 Document Storage
 ACID Properties
 Compaction
 Views
 Distributed Updates
 Conflict Resolution
3
Technical Overview
So, wtf is CouchDB?
 NoSQL databases
 document store
 distributed architecture
 easy replication
4
Technical Overview
Document Storage
 use append-only files
 documents stored as JSON
 access via RESTful HTTP API
 map-reduce functions (Javascript) for views
5
Technical Overview
ACID Properties
 commitment system features all ACID properties
 never overwrite committed data (append-only)
 no shutdown process
 no “repair” command needed (Clap!!!)
6
Technical Overview
ACID Properties (2)
 document updates are serialized
 readers never have to wait on writers, even on
the same document
 Multi-version Concurrency Control (MVCC)
 additional sequence IDs (_rev) are used
7
Technical Overview
ACID Properties (3)
 2-step commit:
Step 1: Document data & associated index updates are
flushed to disk (append to file).
Step 2: The updated database header is written in
two consecutive, identical chunks
to make up the first 4 KB of the file
 Handling failures:
Case 1: Partially flushed updates are simply ignored
Case 2: The surviving copy is used
8
Technical Overview
ACID Properties (3)
9
Technical Overview
Compaction
 data cloned to a new file
 redundant data are removed
 no downtime required
10
Technical Overview
Views
 allow aggregating and reporting on documents
 use Javascript map-reduce functions
 view indexes are built only once and updated
incrementally
11
Technical Overview
Distributed Updates
 Peer-based distributed database system
 Incremental replication
(partial replication is allowed)
 Peers access & update the same data while
disconnected
 need for conflict resolution after replication
12
Technical Overview
Conflict Resolution
 allow for decentralized conflict resolution
 preserve single document semantics
 conflicting documents are also replicated
 after replication, one revision will be picked as the
“winner” by a deterministic algorithm so that the
same choice will be made on all peers
 other revisions are marked as _deleted, and will
not be removed during compaction.
13
Technical Overview
Conflict Resolution (2)
 Get conflicting revisions:
GET /db/doc_id?conflicts=true
 Fetch a history revision:
GET /db/doc_id?rev=xxxx
14
Consistency Model
 The CAP theorem
 Local Consistency
 Validation
15
Consistency Model
The CAP Theorem
16
Consistency Model
Local Consistency
 No Locking
17
Consistency Model
Validation
 Javascript functions are used for validation
 Context information is provided
 Updates can be approved or denied
18
Live Demo
 CRUD
 Views
19
References
 Apache CouchDB 1.6 documentation
http://docs.couchdb.org/en/1.6.x/
 Karel Minařík presentation at WebExpo2010
http://webexpo.net/prague2010/talk/couchdb-database-for-the-web/
 Introduction to REST & CouchDB, ULM University
http://www.slideshare.net/partlycloudy/introduction-to-rest-couchdb
20

Apache CouchDB

  • 1.
    Apache CouchDB Course: AdvancedDatabases Group 5: Trinh Phuc Tho, Vo Quoc Khanh, Hoang Trung Hieu 1
  • 2.
    What to expect? Technical Overview  Consistency Model  Live Demo 2
  • 3.
    Technical Overview  DocumentStorage  ACID Properties  Compaction  Views  Distributed Updates  Conflict Resolution 3
  • 4.
    Technical Overview So, wtfis CouchDB?  NoSQL databases  document store  distributed architecture  easy replication 4
  • 5.
    Technical Overview Document Storage use append-only files  documents stored as JSON  access via RESTful HTTP API  map-reduce functions (Javascript) for views 5
  • 6.
    Technical Overview ACID Properties commitment system features all ACID properties  never overwrite committed data (append-only)  no shutdown process  no “repair” command needed (Clap!!!) 6
  • 7.
    Technical Overview ACID Properties(2)  document updates are serialized  readers never have to wait on writers, even on the same document  Multi-version Concurrency Control (MVCC)  additional sequence IDs (_rev) are used 7
  • 8.
    Technical Overview ACID Properties(3)  2-step commit: Step 1: Document data & associated index updates are flushed to disk (append to file). Step 2: The updated database header is written in two consecutive, identical chunks to make up the first 4 KB of the file  Handling failures: Case 1: Partially flushed updates are simply ignored Case 2: The surviving copy is used 8
  • 9.
  • 10.
    Technical Overview Compaction  datacloned to a new file  redundant data are removed  no downtime required 10
  • 11.
    Technical Overview Views  allowaggregating and reporting on documents  use Javascript map-reduce functions  view indexes are built only once and updated incrementally 11
  • 12.
    Technical Overview Distributed Updates Peer-based distributed database system  Incremental replication (partial replication is allowed)  Peers access & update the same data while disconnected  need for conflict resolution after replication 12
  • 13.
    Technical Overview Conflict Resolution allow for decentralized conflict resolution  preserve single document semantics  conflicting documents are also replicated  after replication, one revision will be picked as the “winner” by a deterministic algorithm so that the same choice will be made on all peers  other revisions are marked as _deleted, and will not be removed during compaction. 13
  • 14.
    Technical Overview Conflict Resolution(2)  Get conflicting revisions: GET /db/doc_id?conflicts=true  Fetch a history revision: GET /db/doc_id?rev=xxxx 14
  • 15.
    Consistency Model  TheCAP theorem  Local Consistency  Validation 15
  • 16.
  • 17.
  • 18.
    Consistency Model Validation  Javascriptfunctions are used for validation  Context information is provided  Updates can be approved or denied 18
  • 19.
  • 20.
    References  Apache CouchDB1.6 documentation http://docs.couchdb.org/en/1.6.x/  Karel Minařík presentation at WebExpo2010 http://webexpo.net/prague2010/talk/couchdb-database-for-the-web/  Introduction to REST & CouchDB, ULM University http://www.slideshare.net/partlycloudy/introduction-to-rest-couchdb 20