Portland Developing with Couchbase I: Getting Started
 

Portland Developing with Couchbase I: Getting Started

on

  • 703 views

 

Statistics

Views

Total Views
703
Views on SlideShare
703
Embed Views
0

Actions

Likes
0
Downloads
6
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • By design, installation of couchbase server is easy.
  • Again, quick. show it is all simple:gem install, easy_install, peclisntall, mvnisnstall, etc ...
  • TODO: replace couchbase server with a logo
  • 1. _ids2. ignore _rev3. data types
  • TODO: find a real brewery documentThere is a different schema between this beer and it's brewery. Obviously, there is a relationship but while a beer has an address, it's pretty temporary. A brewery probably technically has an alcohol by volume, but it's not commonly measured or tracked.
  • GetSetDeleteAdd/Replace
  • [FIXME] Title

Portland Developing with Couchbase I: Getting Started Portland Developing with Couchbase I: Getting Started Presentation Transcript

  • Developing with Couchbase Part I: Getting Started John Zablocki Developer Advocate @codevoyeur 1
  • GETTING STARTED:DEVELOPMENT ENVIRONMENT 2
  • Development Environment: Development DB• Downloads at couchbase.com/download • Linux: Ubuntu and Red Hat/CentOS – Packages for most common distributions. • dpkg -i , rpm -i, etc. • Mac – Download a .zip, open, drag to Applications, • Windows – Download a setup.exe, double click • Provision via wizard in Web Console – Or provision via REST interface: operations folks to automate provisioning (i.e Chef, puppet, Rightscale rightscript) 3
  • Development Environment: Obtaining a Client• High performance, official client libraries for Java, .NET, PHP, Ruby, C, Python*• Head to couchbase.com/develop for SDKs where you will find – Client libraries – Screencasts on Getting Started – Getting started guides – Tutorial with a sample application – A complete API reference *Current version 0.6 as of 2012-03-13 4
  • Client Setup: Getting Cluster Configuration Couchbase Client Cluster Configuration over REST {
… "bucketCapabilities": [
 "touch", 
 "sync", 
 "name": "default", 
 "nodeLocator": "vbucket", 
 …. http://myserver:8091/pools Couchbase Couchbase Couchbase Couchbase Server Server Server Server Node Node Node Node 5
  • Client at Runtime: Adding a node Couchbase Client New node Cluster coming online Topology UpdateCouchbase Couchbase Couchbase Couchbase Couchbase Server Server Server Server Server Node Node Node Node Node 6
  • Client Set up at a Code Level// Set up at least two URIs in case one server failsURI oneserver = new URI("http://10.1.6.171:8091/pools/");URI twoserver = new URI("http://10.1.6.172:8091/pools/");List<URI> servers = new ArrayList<URI>();servers.add(oneserver);servers.add(twoserver);// Now create a client talking to the default bucketCouchbaseClient cbc = new CouchbaseClient(servers, "default", "");System.err.println(cbc.get(“JohnZablocki") + " is off developing with Couchbase!"); Use the Java client with your favorite JSON library: Jettison, Google GSON, etc. 7
  • Operations Available to a Client of Couchbase Server• Store Operations – Add: Store the document if it does not yet exist – Set: Store the document, overwriting existing if necessary• Retrieve Operations – Get: Fetch the document – Get and touch: Fetch the document and update the TTL – Multiget: Fetch multiple documents at the same time• Update operations – Append/prepend: Add data in front of or on the end of a document – Delete: Remove the document from the store – Compare and Swap (CAS): Replace the current document, if CAS matches – Replace: Replace the document if it exists, otherwise do not – Touch: Update the TTL for a document 8
  • Common Questions with MetadataDocument Metadata:• TTL• CAS value• FlagsQ: What happens to a document persisted after it’s TTL?A: A regular background job will remove expired documents.Q: How do I use flags?A: Frequently used to identify data type or other attributes, such ascompression. Behavior varies from client to client. 9
  • Distributed System Design: Concurrency Controls Actor 1 Actor 2 • Compare and Swap Operations – Often referred to as “CAS” – Optimistic concurrency control Success CAS mismatch – Available with many mutation operations, depending on client. • Get with Lock Couchbase Server – Often referred to as “GETL” – Pessimistic concurrency control – Locks have a short TTL A – Locks released with CAS operations – Useful when working with object B C D graphs F E 10
  • INTRODUCING DOCUMENTS 11
  • A JSON Document The primary key{ "_id": "beer_Hoptimus_Prime", "abv": 10.0, "brewery": "Legacy Brewing Co.", A float "category": "North American Ale", "name": "Hoptimus Prime", "style": "Imperial or Double India Pale Ale", "updated": [2010, 7, 22, 20, 0, 20], "available": true} Date time as array A Boolean 12
  • Other Documents and Document Relationships{ "_id": "beer_Hoptimus_Prime", "abv": 10.0, "brewery": "Legacy Brewing Co.", "category": "North American Ale", "name": "Hoptimus Prime", "style": “Double India Pale Ale", "updated": [2010, 7, 22, 20, 0, 20], "available": true } { "_id": "brewery_Legacy_Brewing_Co", "name" : "Legacy Brewing Co.", "address": "525 Canal Street Reading, Pennsylvania, 19601 United States", "updated": "2010-07-22 20:00:20", "latitude": -75.928469, "longitude": 40.325725} 13
  • Adding (a document) to the Bucket of Beers • Simply create the document, then add <?php include "Couchbase.php"; $cb = new Couchbase; $cb->addCouchbaseServer("http://localhost:8091"); // defaults to the “default” bucket // a very simple brew $mybrew = new stdObj; $mybrew->brewery = "The Kitchen"; $cb->set("beer_My_Brew", json_encode($mybrew)); 14
  • Simplicity of Document Oriented Datastore• Schema is optional – Technically, each document has an implicit schema – Extend the schema at any time! • Need a new field? Add it. Define a default for similar objects which may not have this field yet.• Data is self-contained – Documents more naturally support the world around you, the data structures around you• Model data for your App/Code instead for the Database 15
  • Adding a Document: Observations and Considerations• Observations – Conversion to document was very simple, many JSON options – Flexible schema: Did not need to add the latitude and longitude of Matt’s kitchen – Flexible schema: Can add the brewery detail later• Considerations – Why use a particular key/_id : "beer_My_Brew” – Should I have a TTL? 16
  • Common Questions when Adopting CouchbaseQ: What if I need to fetch referenced documents?A: Simply get them one after another. It’s very fast owing to our cache andstorage model.Q: How can I update just a small portion of a document?A: The best approach is to keep the document model live in your application, thenuse CAS operations to store modified documents. The Ruby sample applicationhas a good example.Q: I currently use serialized objects with memcached or Membase, can I do this stillwith Couchbase Server?A: Absolutely! Everything previously supported and used is still there. JSON offersadvantages with heterogenenous platform support and preparing for Couchbase2.0 views. 17
  • COUCHBASE SERVER 2.0COMPATIBLE LIBRARY FEATURES 18
  • Couchbase Server 2.0: Views • Views can spread a few different uses – Simple secondary indexes (the most common) – Aggregation functions • Example: count the number of North American Ales – Organizing related data 19
  • Q&A 21
  • OTHER EXAMPLE DOCUMENTS 22
  • Storing a Message DocumentDocument:{ "from": "user_512", "to": "user_768", "text": "Hey, that Beer you recommended is pretty fab, thx!" "sent_timestamp": 1326476560}<?php// store it$cb = new Couchbase;$cb->addCouchbaseServer("localhost");$cb->set("message_1024", $message); 23
  • User Profile Document{ "user_id": 512, "name": "Beer Likington", "email": "beer.like@gmail.com", "sign_up_timestamp": 1224612317, "last_login_timestamp": 1245613101}{ "user_id": 768, "name": "Simon Neal", "email": "sneal@gmail.com", "sign_up_timestamp": 1225554317, "last_login_timestamp": 1234166701, "country": "Scotland", "pro_account" true, "friends": [512, 666, 742, 1111]} 24
  • Game Score Document{ "game_id": 12415115, "scores": { "user_a": { "user_id": 512, "score_a": 1, "score_b": 57, "score_c": 24 }, "user_b": { "user_id": 768, "score_a": 3, "score_b": 67, "score_c": 15 } }, "score_timestamp": 1348560842} 25
  • Photo Metadata Document{ "photo_id": "ccbcdeadbeefacee", "size": { "w": 500, "h": 320, "unit", "px" }, "exposure: "1/1082", "aperture": "f/2.4", "flash": false, "camera": { "name": "iPhone 4S", "manufacturer": "Apple", } "user_id": 512, "timestamp": [2011, 12, 13, 16, 31, 07]} 26