cs 510 – fall 2011 andy phenix khanh nguyen elakkiya...
TRANSCRIPT
CouchDBCS 510 – Fall 2011
Andy PhenixKhanh Nguyen
Elakkiya PandianSharmadha Moorthy
Anitha Suryanarayan
Why use CouchDB● Store complex data structures - JSON● Store variable data structures - no schema● De-normalized / self contained● Add attachments to documents● Scalable and fault tolerant
● Better fit for certain problem domains○ Messaging○ CMS
Data Model■ Self Contained Documents - JSON
■ View engine - JavaScript
■ Consistency: Atomic, conflicts resolved by clients.
■ Querying and Indexing : based on Map-Reduce
■ Lock Free Design and eventual consistency
Data Model
■ RESTful HTTP /JSON API accessible from many programming libraries and tools
■ API Types ○ Server level○ Database level○ Document level
API's
unsigned long addr = 0xff00ff20;unsigned int block = addr & 0x1f;unsigned int set = (addr & 0x7e0) >> 5;unsigned int tag = (addr & 0xfffff800) >> 11;
Code Sample DescriptionGET /somedatabase/some_doc_id?rev=946B7D1C HTTP/1.0 To retrieve a document.
GET /somedatabase/some_doc_id?rev=946B7D1C HTTP/1.0 See Document Revisions for additional notes on revisions.
HEAD /somedatabase/some_doc_id HTTP/1.0 Returns basic information about the document, including its current revision.
PUT /somedatabase/some_doc_id HTTP/1.0Content-Length: 245Content-Type: application/json{"Subject":"I like Plankton","Author":"Rusty","PostedDate":"2006-08-15T17:30:12-04:00","Tags":["plankton", "baseball", "decisions"],"Body":"I decided today that I don't like baseball. I like plankton."}
To create/update a named document.
POST /somedatabase/ HTTP/1.0Content-Length: 245Content-Type: application/json{"Subject":"I like Plankton","Author":"Rusty","PostedDate":"2006-08-15T17:30:12-04:00","Tags":["plankton", "baseball", "decisions"],"Body":"I decided today that I don't like baseball. I like plankton."}
Create a new document with a server generated DocID
DELETE /somedatabase/some_doc?rev=1582603387 HTTP/1.0 To delete a document.
COPY /somedatabase/some_doc HTTP/1.1Destination: some_other_doc Copy documents
Data Model■ JSON
○ Example of a JSON document:
{
"_id":"discussion_tables",
"_rev":"D1C946B7",
"FullHours":[1,2,3,4,5,6,7,8,9,10],
"Activities": [
{"Name":"Football", "Duration":2, "DurationUnit":"Hours"},
{"Name":"Breakfast", "Duration":40, "DurationUnit":"Minutes", "Attendees":["Jan", "Damien", "Laura", "Gwendolyn"]}
]
}
Query Support● Functional Query Language
● Views ○ Map-reduce functions ○ indexed with specific key fields○ Stored in a B-Tree structure
● Automatic Query Optimization
Query SupportTypes of Queries
● Range Queries■ Very efficient; Efficiency O(log N)■ B-trees for document and index storage
● Point, Navigation and Arbitrary Queries■ Supported if appropriate indexes are built.■ Search without indexed key are not supported in
CouchDB.
Query Support● Sample query request from a view:
Point based : /blog/_design/docs/_view/by_date?key="2009/01/30 18:04:11”
Range based : /blog/_design/docs/_view/by_date?startkey="2010/01/01 00:00:00"&endkey="2010/02/00 00:00:00“
Indexes● B-Tree Structure
● Types : ○ Document index○ View index
● Automatic management by Couch DB View server
Example map Function
Key (indexed)– (item,price)
Value - store
Example map Function
Key (indexed)– (item,price)
Value - store
Storage● Append only file structure
● B-tree with two header copies
● “Crash-only” design - protects data integrity
● Flexible - can run on smart phone to a cluster
Transactions & Concurrency Control
● Only within single document
● ACID semantics
● MVCC - “optimistic locking”
● Lock-free design
● Writes serialized when data is actually written to the disk.
Transactions and Concurrency Control
● eventual consistency by incremental replication
● 'shared nothing' cluster
● no single point of contention
Scalability● Horizontal scaling via replication
● Map-reduce queries
● Partitioning via add-ons○ Lounge○ Pillow○ BigCouch
Replication● Asynchronous● Flexible Schemes● User-initiated via HTTP request
○ Specifies Source -> Target
● Client Application Resolves Conflicts● Limited Support for Automation
Platform● POSIX systems - GNU/Linux and OS X
○ Windows is not officially supported
● Cloud Infrastructure○ Apache○ Cloudant○ Iris couch○ Amazon Machine Images
Platform/Deployment● Language binding
○ C,C#,ColdFusion,Erlang,ExtJS,Haskell○ Java,Javascript,LISP,LotusScript,Lua,NodeJS,Objective-C○ Ocaml,Perl,PHP,Python,Ruby,Smalltalk,Vmware
● Communication Protocols○ RESTful HTTP methods - POST, GET, PUT ,DELETE○ cURL ○ Encoding - JSON
Platform/Deployment● Lounge
● CouchRest ○ CouchRest-ExtendedDocument
● A CouchApp
● Couch potato
● CouchFoo
References
http://wiki.apache.org/couchdb/FrontPagehttp://en.wikipedia.org/wiki/Couchdbhttp://sitr.us/2009/09/13/couchdb-notes.htmlhttp://wiki.apache.org/couchdb/Frequently_asked_questionshttp://www.oscon.com/oscon2009/public/schedule/detail/8076http://guide.couchdb.org/editions/1/enhttp://www.couchbase.com/customers/case-studies