Apache CouchDB

20
Apache CouchDB Course: Advanced Databases Group 5: Trinh Phuc Tho, Vo Quoc Khanh, Hoang Trung Hieu 1

description

The presentation provided by my study group on the Advanced DB course at FPT University, HCMC, Vietnam.

Transcript of Apache CouchDB

Page 1: Apache CouchDB

Apache CouchDB

Course: Advanced DatabasesGroup 5: Trinh Phuc Tho, Vo Quoc Khanh, Hoang Trung Hieu

1

Page 2: Apache CouchDB

What to expect?

Technical Overview

Consistency Model

Live Demo

2

Page 3: Apache CouchDB

Technical Overview

Document Storage

ACID Properties

Compaction

Views

Distributed Updates

Conflict Resolution

3

Page 4: Apache CouchDB

Technical Overview

So, wtf is CouchDB?

NoSQL databases

document store

distributed architecture

easy replication

4

Page 5: Apache CouchDB

Technical Overview

Document Storage

use append-only files

documents stored as JSON

access via RESTful HTTP API

map-reduce functions (Javascript) for views

5

Page 6: Apache CouchDB

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

Page 7: Apache CouchDB

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

Page 8: Apache CouchDB

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 chunksto make up the first 4 KB of the file

Handling failures:Case 1: Partially flushed updates are simply ignoredCase 2: The surviving copy is used

8

Page 9: Apache CouchDB

Technical Overview

ACID Properties (3)

9

Page 10: Apache CouchDB

Technical Overview

Compaction

data cloned to a new file

redundant data are removed

no downtime required

10

Page 11: Apache CouchDB

Technical Overview

Views

allow aggregating and reporting on documents

use Javascript map-reduce functions

view indexes are built only once and updated incrementally

11

Page 12: Apache CouchDB

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

Page 13: Apache CouchDB

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

Page 14: Apache CouchDB

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

Page 15: Apache CouchDB

Consistency Model

The CAP theorem

Local Consistency

Validation

15

Page 16: Apache CouchDB

Consistency Model

The CAP Theorem

16

Page 17: Apache CouchDB

Consistency Model

Local Consistency

No Locking

17

Page 18: Apache CouchDB

Consistency Model

Validation

Javascript functions are used for validation Context information is provided Updates can be approved or denied

18

Page 19: Apache CouchDB

Live Demo

CRUD

Views

19

Page 20: Apache CouchDB

References

Apache CouchDB 1.6 documentationhttp://docs.couchdb.org/en/1.6.x/

Karel Minařík presentation at WebExpo2010http://webexpo.net/prague2010/talk/couchdb-database-for-the-web/

Introduction to REST & CouchDB, ULM Universityhttp://www.slideshare.net/partlycloudy/introduction-to-rest-couchdb

20