NoSQL CGN: CouchDB (11/2011)

Click here to load reader

download NoSQL CGN: CouchDB (11/2011)

of 26

  • date post

    26-Dec-2014
  • Category

    Technology

  • view

    1.265
  • download

    2

Embed Size (px)

description

Kleine Einführung in CouchDB auf der NoSQL Usergroup Cologne am 2.11.2011.

Transcript of NoSQL CGN: CouchDB (11/2011)

  • 1. Relax! Sebastian Cohnen @tisba / tisba.deMittwoch, 16. November 11
  • 2. About Me Freier Entwickler Ruby/Rails & node.js Performance & Scalability Engineering Distributed Load Testing CouchDB, Redis & Riak und ebenfalls interessiert an Erlang, AMQP, ...Mittwoch, 16. November 11
  • 3. Users of Couchdb BBC meebo UbuntuOne ... adcloudMittwoch, 16. November 11
  • 4. CouchDB: Basics Schema-frei Dokumenten-orientiert Key/Value-Speicher fehlertolerant & robustMittwoch, 16. November 11
  • 5. Key Features HTTP + JSON Multi-Master Replikation AP aus CAP Append-only inkrementelle, materialisierte Views (map/reduce)Mittwoch, 16. November 11
  • 6. HTTP & JSONMittwoch, 16. November 11
  • 7. Admin InterfaceMittwoch, 16. November 11
  • 8. Create A Database $ curl -w%{http_code} -X PUT http://127.0.0.1:5984/test_db {"ok":true} 201 $ $ curl -w%{http_code} -X GET http://127.0.0.1:5984/test_db {"db_name":"test_db","doc_count":0,"doc_del_count":0, "update_seq":1,"purge_seq":0, "compact_running":false, "disk_size":16473, "instance_start_time": "1253091887127542","disk_format_version":4} 200 * $ alias curl=curl -w%{http_code} -XMittwoch, 16. November 11
  • 9. create A Document $ curl POST -d {"hello":"world"} http://127.0.0.1:5984/ test_db {"ok":true,"id":"67729d5013cf3f8858eb29cb17e5a723","rev":"1-1 5f65339921e497348be384867bb940f"} 201 read $ curl GET http://127.0.0.1:5984/test_db/ 67729d5013cf3f8858eb29cb17e5a723 {"_id":"67729d5013cf3f8858eb29cb17e5a723","_rev":"1-15f653399 21e497348be384867bb940f","hello":"world"} 200Mittwoch, 16. November 11
  • 10. update $ curl PUT -d {"_rev":"1-15f65339921e497348be384867bb940f", "hello":"world","message":"about to show CRUD in couch"} http://127.0.0.1:5984/test_db/ 2f41f56816191b94ecbd127151faa242 {"ok":true,"id":"2f41f56816191b94ecbd127151faa242","rev":"2-2 873c60120aa6dbe2204cd2c1a0e8722"} 201 $ curl GET http://127.0.0.1:5984/test_db/ 2f41f56816191b94ecbd127151faa242 {"_id":"2f41f56816191b94ecbd127151faa242","_rev":"2-2873c6012 0aa6dbe2204cd2c1a0e8722","hello":"world","message":"about to show CRUD in couch"} 200Mittwoch, 16. November 11
  • 11. delete $ curl DELETE http://127.0.0.1:5984/test_db/ 67729d5013cf3f8858eb29cb17e5a723? rev=1-15f65339921e497348be384867bb940f {"ok":true,"id":"67729d5013cf3f8858eb29cb17e5a723","rev":"2-2 d715caed35974bb33de24d1d6c95779"} 200 $ curl GET http://127.0.0.1:5984/test_db/ 67729d5013cf3f8858eb29cb17e5a723 {"error":"not_found","reason":"deleted"} 404Mittwoch, 16. November 11
  • 12. CouchApps Dokumente knnen Attachments haben CouchDB als HTTP Server HTML+CSS+JS ausgeliefert von CouchDB greift via HTTP auf CouchDB als Datenbank zu Beispiel: Kabul War Diary http://upondata.com:5984/afgwar/_design/afgwardiary/ index.htmlMittwoch, 16. November 11
  • 13. ReplikationMittwoch, 16. November 11
  • 14. Replikation Replikation luft via HTTP asynchron inkrementell (online-ofine) automatische Koniktlsung Multi-Version Concurrency Control (MVCC) Multi-Master als default lterbarMittwoch, 16. November 11
  • 15. Map/Reduce ViewsMittwoch, 16. November 11
  • 16. Accessing Data direkter Zugriff via http://server/DATABASE/DOC-ID materialisierte Views bestehen aus einer map-Phase und einer optionalen reduce-Phase show & list: (Dokument) Transformationen lters, externals, ...Mittwoch, 16. November 11
  • 17. Views sortiert, inkrementell, efzienter Zugriff via B-Trees build-in Viewserver: JavaScript (Spidermonkey) Erlang 3rd Party Viewserver in Ruby, Python, Java, Perl, ...Mittwoch, 16. November 11
  • 18. map/reduce map: Eine Funktion, welche key/value Paare in einen Index schreibt Beispiel Tag-Cloud: 1 function(doc) { 2 if (doc.tags) { 3 for(var idx in doc.tags) { 4 emit(doc.tags[idx], 1); 5 } 6 } 7 }Mittwoch, 16. November 11
  • 19. map example {body:[...], tags:[erlang, couchdb]} {body:[...], tags:[couchdb, talk, rails]} map-function(doc) {key:couchdb, value:1} {key:couchdb, value:1} {key:erlang, value:1} {key:rails, value:1} {key:talk, value:1} * indices are automatically sortedMittwoch, 16. November 11
  • 20. map/reduce reduce wird verwendet, um das Ergebnis der map- Phase zu verarbeiten 1 function(keys, values, rereduce) { 2 return sum(values); 3 }Mittwoch, 16. November 11
  • 21. reduce example {key:erlang: value:1} {key:couchdb: value:1} {key:couchdb: value:1} {key:talk: value:1} {key:rails: value:1} reduce function(...