CouchConf London Developing with Couchbase I: Getting Started
 

CouchConf London Developing with Couchbase I: Getting Started

on

  • 676 views

 

Statistics

Views

Total Views
676
Views on SlideShare
676
Embed Views
0

Actions

Likes
0
Downloads
14
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

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

CouchConf London Developing with Couchbase I: Getting Started CouchConf London Developing with Couchbase I: Getting Started Presentation Transcript

  • Developing  with  Couchbase  Part  I:   Ge:ng  Started   Raghavan  “Rags”  Srinivas   Developer  Advocate   rags@couchbase.com   1  
  • Speaker  IntroducQon  •  Architect  and  Evangelist  working  with  developers  •  Speaker  at  JavaOne,  RSA  conferences,  Sun  Tech  Days,   JUGs  and  other  developer  conferences  •  Taught  undergrad  and  grad  courses  •  Technology  Evangelist  at  Sun  Microsystems  for  10+   years  •  SQll  trying  to  understand  and  work  more  effecQvely  on   Java  and  distributed  systems  •  Couchbase  Developer  Advocate  working  with  Java  and   Ruby  developers  •  Philosophy:  “Be#er  to  have  an  unanswered  ques1on   than  a  unques1oned  answer”   2  
  • Agenda  •  Ge:ng  Started  •  An  introducQon  to  Documents  with  Couchbase  •  Couchbase  server  2.0  compaQble  client  libraries  •  Resources  and  Summary  •  Q/A   3  
  • GETTING  STARTED:  DEVELOPMENT  ENVIRONMENT   4  
  • Development  Environment:  Development  DB  •  Downloads  at  couchbase.com/download   •  Linux:  Ubuntu  and  Red  Hat/CentOS   –  Packages  for  most  common   distribuQons.   •  dpkg  -­‐i  ,  rpm  -­‐i,  etc.   •  Mac   –  Download  a  .zip,  open,  drag  to   ApplicaQons,   •  Windows   –  Download  a  setup.exe,  double  click   •  Provision  via  wizard  in  Web  Console   –  Or  provision  via  REST  interface:  operaQons  folks  to  automate  provisioning     (i.e  Chef,  puppet,  Rightscale  rightscript)   5  
  • 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  Ge:ng  Started   –  Ge:ng  started  guides   –  Tutorial  with  a  sample  applicaQon   –  A  complete  API  reference   *Current  version  0.6  as  of  2012-­‐03-­‐13   6  
  • Client  Setup:  Ge:ng  Cluster  ConfiguraQon   Couchbase  Client   Cluster  ConfiguraQon   over  REST   { … "bucketCapabilities": [h2p://myserver:8091/   "touch", "sync", "couchapi" ], "bucketCapabilitiesVer": "sync-1.0", "bucketType": ”couchbase", "name": "default", "nodeLocator": "vbucket", "nodes": [ ….   Couchbase   Couchbase   Couchbase   Couchbase   Server   Server   Server   Server   Node   Node   Node   Node   7  
  • Client  at  RunQme:  Adding  a  node   Couchbase  Client   New  node     Cluster  coming  online   Topology Update Couchbase   Couchbase   Couchbase   Couchbase   Couchbase   Server   Server   Server   Server   Server   Node   Node   Node   Node   Node   8  
  • Client  Set  up  at  a  Code  Level  // Set up at least two URIs in case one server fails!URI server = new URI("http://10.1.6.171:8091/pools/");!List<URI> servers = new ArrayList<URI>();
servers.add(server);!!!// Now create a client talking to the default bucket!CouchbaseClient cbc = 
 new CouchbaseClient(servers, "default", "");!!System.err.println(cbc.get(“Rags") + ! " is off Minding the Gap!!");! Use  the  Java  client  with  your  favorite  JSON  library:  Je@son,  Google  GSON,  etc.   Use  other  client  libraries  such  as  yajl  for  Ruby   9  
  • OperaQons  Available  to  a  Client  of  Couchbase  Server  •  Store  OperaQons   –  Add:  Store  the  document  if  it  does  not  yet  exist   –  Set:  Store  the  document,  overwriQng  exisQng  if  necessary  •  Retrieve  OperaQons   –  Get:  Fetch  the  document   –  Get  and  touch:  Fetch  the  document  and  update  the  TTL   –  MulQget:  Fetch  mulQple  documents  at  the  same  Qme  •  Update  operaQons   –  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   Note:  Not  all  Client  Libraries  are  created  equal   10  
  • A  Distributed  Hash  Table   ApplicaQon   set(key,  value)   get(key)   returns  value   Database   DData   Cluster   11  
  • A  Distributed  Hash  Table  Document  Store   ApplicaQon   set(key,  json)   get(key)   returns  json   Database  { ! DData  “id": ”brewery_Legacy”,!“type” : “brewery”,!"name" : "Legacy Brewing”,!“address": "525 Canal Street Reading",
"updated": "2010-07-22 20:00:20",
}! Cluster   12  
  • Distributed  System  Design:  Concurrency  Controls   Actor  1   Actor  2   •  Compare  and  Swap  OperaQons   –  Olen  referred  to  as  “CAS”   –  OpQmisQc  concurrency  control   Success   CAS  mismatch   –  Available  with  many  mutaQon   operaQons,  depending  on  client.   •  Get  with  Lock   Couchbase  Server   –  Olen  referred  to  as  “GETL”   –  PessimisQc  concurrency  control   –  Locks  have  a  short  TTL   A   –  Locks  released  with  CAS   operaQons   –  Useful  when  working  with  object   B   C   D   graphs   F   E   13  
  • Common  QuesQons  with  Metadata   Document  Metadata:   •  TTL   •  CAS  value   •  Flags  Q:  What  happens  to  a  document  persisted  aKer  it’s  TTL?  A:  A  regular  background  job  will  remove  expired  documents.    Q:  How  do  I  use  flags?  A:  Frequently  used  to  idenQfy  data  type  or  other  anributes,  such  as  compression.    Behavior  varies  from  client  to  client.   14  
  • INTRODUCING  DOCUMENTS   15  
  • A  JSON  Document   The primary key {! “id": "beer_Hoptimus_Prime",! “type”: “beer”,! "abv": 10.0,! The type information "brewery": "Legacy Brewing Co.",! A float "category": "North American Ale",! "name": "Hoptimus Prime",! "style": "Imperial or Double India Pale Ale",!}! 16  
  • Other  Documents  and  Document  RelaQonships  { ! “id": "beer_Hoptimus_Prime",! “type” : “beer”, ! "abv": 10.0,! "brewery": ”brewery_Legacy_Brewing_Co",! "category": "North American Ale",! "name": "Hoptimus Prime",! "style": “Double India Pale Ale”!}! { ! “id": ”brewery_Legacy_Brewing_Co”,! “type” : “brewery”,! "name" : "Legacy Brewing Co.",
 "address": "525 Canal Street Reading, Pennsylvania, 19601 United States",
 Afterthought "updated": "2010-07-22 20:00:20",
 "latitude": -75.928469,
 "longitude": 40.325725! }! 17  
  • Simplicity  of  Document  Oriented  Datastore  •  Schema  is  opQonal   –  Technically,  each  document  has  an  implicit  schema   –  Extend  the  schema  at  any  Qme!   •  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   18  
  • Adding  a  Document:  ObservaQons  and  ConsideraQons  •  ObservaQons   –  Conversion  to  document  was  very  simple,  many  JSON  opQons   –  Flexible  schema:  Did  not  need  to  add  the  laQtude  and  longitude    to   every  record   –  Flexible  schema:  Can  add  the  brewery  detail  later    •  ConsideraQons   –  Use  a  “type”  field  for  high  level  filtering  on  object  types   –  Why  use  a  parQcular  key/_id  :   ”beer_My_Brew”! –  Should  I  have  a  TTL?   19  
  • Common  QuesQons  when  AdopQng  Couchbase  Q:  What  if  I  need  to  fetch  referenced  documents?  A:  Simply  get  them  one  aler  another  or  use  another  View.        Q:  How  can  I  update  just  a  small  por1on  of  a  document?  A:  The  best  approach  is  to  keep  the  document  model  live  in  your  applicaQon,  then  use  CAS  operaQons  to  store  modified  documents.    The  Ruby  sample  applicaQon  has  a  good  example.    Q:  I  currently  use  serialized  objects  with  memcached  or  Membase,  can  I  do  this  s1ll  with  Couchbase  Server?  A:  Absolutely!    Everything  previously  supported  and  used  is  sQll  there.    JSON  offers  advantages  with  heterogenenous  plasorm  support  and  preparing  for  Couchbase  2.0  views.   20  
  • COUCHBASE  SERVER  2.0    COMPATIBLE  LIBRARY  FEATURES   21  
  • Couchbase  Server  2.0:  Views   •  Views  can  cover  a  few  different  use  cases   –  Simple  secondary  indexes  (the  most  common)   –  AggregaQon  funcQons   •  Example:  count  the  number  of  North  American  Ales   –  Organizing  related  data   22  
  • Indexing  and  Querying   APP  SERVER  1   APP  SERVER  2   APP  SERVER  1   APP  SERVER  2               COUCHBASE  CLIENT  LIBRARY     COUCHBASE  CLIENT  LIBRARY         COUCHBASE  CLIENT  LIBRARY         COUCHBASE  CLIENT  LIBRARY     § Indexing  work  is  distributed             CLUSTER  MAP  MAP   CLUSTER         CLUSTER  MAP   AP   CLUSTER  M     amongst  nodes               §  Large  data  set  possible       §  Parallelize  the  effort   § Each  node  has  index  for  data   Query Response     stored  on  it   § Queries  combine  the  results   from  required  nodes   SERVER  1   SERVER  2   SERVER  3   AcQve  Docs     AcQve  Docs     AcQve  Docs         Doc  5   DOC     Doc  4   DOC     Doc  1   DOC           Doc  2   DOC     Doc  7   DOC     Doc  3   DOC           Doc  9   DOC     Doc  8   DOC     Doc  6   DOC         Replica  Docs     Replica  Docs     Replica  Docs           Doc  4   DOC   Doc  6   DOC   Doc  7   DOC               Doc  1   DOC   Doc  3   DOC   Doc  9   DOC               Doc  8   DOC   Doc  2   DOC   Doc  5   DOC         23  
  • RESOURCES  AND  SUMMARY   24  
  • Resources,  Summary  and  Call  For  AcQon  •  Couchbase  Server  Downloads   –  hnp://www.couchbase.com/downloads-­‐all   –  hnp://www.couchbase.com/couchbase-­‐server/overview  •  Developing  with  Client  libraries   –  hnp://www.couchbase.com/develop/java/current  (example)  •  Couchbase  forums   –  hnp://www.couchbase.com/forums/     25  
  • THANKS  -­‐  Q&A  Raghavan “Rags” Srinivas, Couchbase Inc.  (rags@couchbase.com, @ragss) 26