Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Riak Training (introduction) トレーニング 1. 基本編

Riak Training (introduction) トレーニング 1. 基本編

初日の基本編のスライドです。お問い合わせはこちら> http://basho.co.jp/jp-proserv/

Basho Japan KK

April 28, 2014
Tweet

More Decks by Basho Japan KK

Other Decks in Technology

Transcript

  1. ˜#BTIP5FDIOPMPHJFT*OD"MM3JHIUT3FTFSWFE  3JBLͱ͸ •  ଱ো֐ੑɿো֐࣌Ͱ΋͔ͳΒͣίϐʔΛݸ΋ͭ •  ֦ுੑɿεέʔϧΞ΢τɺϦχΞͳ༧ଌՄೳੑ •  ଎౓ɿϨΠςϯγॏࢹ • 

    Մ༻ੑɿμ΢ϯλΠϜ΄΅ͳ͠ʢ"DU4CZͷ%#ͩͱ ௨ৗ͸ඵҎ্ʣ •  ,74ɿΩʔɾ஋ͷϖΞͰදݱͰ͖ΔσʔλϞσϧ ͕ಛ௃ͷσʔλϕʔε
  2. ˜#BTIP5FDIOPMPHJFT*OD"MM3JHIUT3FTFSWFE  σʔλϕʔεͱ͸ •  ;ͨͭͷٕज़ཁૉͷ૊Έ߹Θ͔ͤΒͳΔٕज़ •  ΫΤϦॲཧʢ2VFSZ1SPDFTTJOHʣ •  σʔλΛग़͠ೖΕ͢ΔͨΊͷΠϯλʔϑΣʔεͷ ࢓༷ͱ࣮૷

    •  ୅දతͳΠϯλʔϑΣʔε͸42- •  τϥϯβΫγϣϯॲཧʢ5SBOTBDUJPO1SPDFTTJOHʣ •  σʔλΛ҆શʹग़͠ೖΕ͢ΔͨΊͷฒߦॲཧɾฒ ྻॲཧͷઃܭͱ࣮૷
  3. ˜#BTIP5FDIOPMPHJFT*OD"MM3JHIUT3FTFSWFE  l/P42-z •  /PU0OMZ42- •  ࣈٛͲ͓ΓͰ͋Ε͹ɺ42-Λ࢖͍ͬͯͳ͍ͱ͍͏ ͚ͩͷҙຯ •  ࠷ۙͰ͸ɺ"$*%ಛੑΛ࣋ͨͳ͍σʔλϕʔε͕

    42-MJLFͳΠϯλʔϑΣʔεΛ͍࣋ͬͯΔ͜ͱ΋ •  "$*%ಛੑΛ࣋ͨͳ͍͜ͱͷ݁Ռͱͯ͠ɺ42-ͱ͍ ͏ΠϯλʔϑΣʔεΛ࢖͏ඞཁ͕ͳ͍৔߹ͱࠞಉ͞ Ε͍ͯΔ
  4. ˜#BTIP5FDIOPMPHJFT*OD"MM3JHIUT3FTFSWFE  "$*%ಛੑΛຬͨ͞ͳ͍ •  "UPNJDJUZ $POTJTUFODZ *TPMBUJPO %VSBCJMJUZͷ͍ ͣΕ͔͕ෆཁͳϢʔεέʔε • 

    ୅ΘΓʹɺεέʔϥϏϦςΟɺ଎౓ɺՄ༻ੑͳͲ͕ ॏࢹ͞ΕΔ৔໘͕͋ΓɺͦΕ͕/P42-ొ৔ͷ͖͔ͬ ͚ͱͳͬͨ •  3JBL͸ͦͷதͰಛʹ%VSBCJMJUZʢӬଓੑ㲈଱ো֐ੑʣ  εέʔϥϏϦςΟɺ଎౓ɺՄ༻ੑ͕ඞཁͳ৔໘Ͱ࢖ ͏σʔλϕʔε •  42-Λ࢖Θͳ͍ͷ͸ͦͷ݁ՌͰ͔͠ͳ͍
  5. ˜#BTIP5FDIOPMPHJFT*OD"MM3JHIUT3FTFSWFE  3JBLͷઃܭϙϦγʔ •  ଱ো֐ੑʢ'BVMUUPMFSBODFʣ σʔλΛઈରʹͳ͘͞ͳ͍ •  ֦ுੑʢ4DBMBCJMJUZʣ αʔόʔ௥ՃͰੑೳͱอଘ༰ྔ޲্ • 

    Մ༻ੑʢ"WBJMBCJMJUZʣ ͍ͭͰ΋σʔλͷಡΈॻ͖͕Ͱ͖Δ •  ӡ༻ͷ༰қੑʢ0QFSBUJPOBMTJNQMJDJUZʣ ༷ʑͳॲཧΛࣗಈͰߦ͍ɺӡ༻खॱ͕γϯϓϧ
  6. ˜#BTIP5FDIOPMPHJFT*OD"MM3JHIUT3FTFSWFE  Ұ࣌ো֐ൃੜ࣌ • Ұ࣌తͳϊʔυো֐ʢOPEFʣ͕ൃੜ • 165 (&5 %&-&5&ϦΫΤετ͸ɺϑ ΥʔϧόοΫϊʔυʢOPEFʣ΁ node  0

      node  1   node  2   node  3   hash(“bucket/key”)   ো֐ൃੜ࣌΋3ݸͷෳ੡Λ ඞͣ࡞Γʢ଱ো֐ੑʣɺ ͔ͭμ΢ϯλΠϜͳ͠ ʢՄ༻ੑʣ
  7. ˜#BTIP5FDIOPMPHJFT*OD"MM3JHIUT3FTFSWFE  2VPSVN •  ౤ථϕʔεͰϨϓϦΧͷ੍ޚΛ͓͜ͳ͏ϓϩτίϧ 8 3/Ͱ࠷৽ͷσʔλ͕ࢀরՄೳ •  /ෳ੡਺ • 

    8XSJUFͷ੒ޭ਺ •  3SFBEͷ੒ޭ਺ XSJUFͱSFBEͷͲͪΒͷύϑΥʔϚϯεΛ༏ઌ͢Δ͔ɻͲΕͩ ͚ϨϓϦΧΛอ͍͔࣋ͨ͠ʹΑͬͯ஋Λௐ੔͢Δ
  8. ˜#BTIP5FDIOPMPHJFT*OD"MM3JHIUT3FTFSWFE  ੔߹ੑΛอͯΔྫอͯͳ͍ྫ • / 8 3ͷ৔߹ 8 3/ 8/Λຬͨ͢ • 

    / 8 3ͷ৔߹ 8 3/ 8/Λຬ ͨ͢  put get put get old new •  N=3, W=2, R=1 ͷ৔߹ W+R > N Λຬ͍ͨͯ͠ͳ͍ put get ݹ͍σʔλΛಡΜͰ͠·͏͔΋
  9. ˜#BTIP5FDIOPMPHJFT*OD"MM3JHIUT3FTFSWFE  Ծ૝ϊʔυ WOPEF㲈ύʔςΟγϣϯ  •  3JBLϊʔυͷ಺෦͸͞ΒʹWOPEFͱݺ͹ΕΔԾ૝ϊʔυ •  ࣮ࡍͷσʔλ͸WOPEF୯ҐͰॲཧ͞ΕΔ • 

    ,FZ͔Βܭࢉ͞Εͨϋογϡ஋ΛݩʹɺରԠWOPEFΛܾఆ OPEF OPEF OPEF OPEF vnode vnode vnode vnode vnode vnode vnode vnode # IBTI #, 
  10. ˜#BTIP5FDIOPMPHJFT*OD"MM3JHIUT3FTFSWFE  2VFSZ •  HFUQVUEFMFUF •  4FDPOEBSZ*OEFY J  • 

    .BQ3FEVDF •  $PVOUFS •  4FBSDI ৄࡉ͸ΞϓϦέʔγϣϯ։ൃͷτϨʔχϯά
  11. ˜#BTIP5FDIOPMPHJFT*OD"MM3JHIUT3FTFSWFE  4FDPOEBSZ*OEFY J  •  ,FZ7BMVFʹରͯ͠෇͚ΒΕΔϝλ৘ใͰʮλάʯͷҰछ •  λάʹ͸ɺόΠφϦ จࣈྻ

    ͷଞʹɺ਺ࣈ͕࢖͑Δ •  λά໊ʹΑΔɺ׬શҰகݕࡧ·ͨ͸ɺൣғݕࡧ͕Մೳ •  ηΧϯμϦΠϯσοΫεʹ֘౰ͨ͠ʮ,FZҰཡʯ͕ಘΒΕΔ 10 20 30 40 A B C age=20͔Β30 initial = B ࡧҾ໊ɿage ࡧҾ໊ɿinitial D
  12. ˜#BTIP5FDIOPMPHJFT*OD"MM3JHIUT3FTFSWFE  ϊʔυ໊ͱFQNE •  &SMBOHͰ͸&SMBOHϊʔυ 7. ىಈ࣌ʹϊʔυ໊Λࢦ ఆ͢Δɹnode_name@[FQDN or hostname

    or IP]! •  ෼ࢄ&SMBOHͰϊʔυؒͰ௨৴Λ͓͜ͳ͏ࡍɺࣝผࢠ ͱͯ͠ϊʔυ໊Λར༻͢Δ •  ෼ࢄ&SMBOH؀ڥͰ͸ϊʔυ໊͔Β࣮ࡍʹόΠϯυ͠ ͍ͯΔ5$1ϙʔτΛ஌ΔͨΊʹ໊લղܾΛߦ͏ •  ໊લղܾ༻ͷϓϩηεͱͯ͠FNQE͕ࣗಈతʹىಈ ͢Δ
  13. ˜#BTIP5FDIOPMPHJFT*OD"MM3JHIUT3FTFSWFE  ෼ࢄ&SMBOH YY FQNE &SMBOHϊʔυ &SMBOHϊʔυ YY FQNE &SMBOHϊʔυ

    &SMBOHϊʔυ name: [email protected] port: 59007 cookie: xjfi2kd9hq name: [email protected] port: 59010 cookie: xjfi2kd9hq name: [email protected] port: 59009 cookie: xjfi2kd9hq name: [email protected] port: 59027 cookie: xjfi2kd9hq [email protected] port: 59009 ڞ༗cookie Λ࢖ͬͯ઀ଓ cookie: xjfi2kd9hq port: 4369 port: 4369
  14. ˜#BTIP5FDIOPMPHJFT*OD"MM3JHIUT3FTFSWFE  ࢀߟ 3JBL্ͷ&SMBOHBQQMJDBUJPO ଟ͘ͷΞϓϦέʔγϣϯʹΑͬͯߏ੒͞Ε͍ͯΔ % grep Application console.log! 2014-03-05

    12:58:59.654 [info] <0.7.0> Application lager started on node '[email protected]'! 2014-03-05 12:58:59.661 [info] <0.7.0> Application sasl started on node '[email protected]'! 2014-03-05 12:58:59.662 [info] <0.7.0> Application crypto started on node '[email protected]'! 2014-03-05 12:58:59.662 [info] <0.7.0> Application public_key started on node '[email protected]'! 2014-03-05 12:58:59.666 [info] <0.7.0> Application ssl started on node '[email protected]'! 2014-03-05 12:58:59.668 [info] <0.7.0> Application riak_sysmon started on node '[email protected]'! 2014-03-05 12:58:59.673 [info] <0.7.0> Application os_mon started on node '[email protected]'! 2014-03-05 12:58:59.682 [info] <0.7.0> Application runtime_tools started on node '[email protected]'! 2014-03-05 12:58:59.695 [info] <0.7.0> Application erlang_js started on node '[email protected]'! 2014-03-05 12:58:59.705 [info] <0.7.0> Application inets started on node '[email protected]'! 2014-03-05 12:58:59.707 [info] <0.7.0> Application mochiweb started on node '[email protected]'! 2014-03-05 12:58:59.711 [info] <0.7.0> Application webmachine started on node '[email protected]'! 2014-03-05 12:58:59.711 [info] <0.7.0> Application basho_stats started on node '[email protected]'! 2014-03-05 12:58:59.715 [info] <0.7.0> Application bitcask started on node '[email protected]'! 2014-03-05 12:58:59.812 [info] <0.7.0> Application riak_core started on node '[email protected]'! 2014-03-05 12:58:59.835 [info] <0.7.0> Application riak_pipe started on node '[email protected]'! 2014-03-05 12:58:59.851 [info] <0.7.0> Application riak_api started on node '[email protected]'! 2014-03-05 12:58:59.853 [info] <0.7.0> Application sidejob started on node '[email protected]'!
  15. ˜#BTIP5FDIOPMPHJFT*OD"MM3JHIUT3FTFSWFE  ϥΠϒϥϦ •  MBHFSϩΪϯάϥΠϒϥϦ •  XFCNBDIJOFNPDIXFC8FCαʔό •  GPMTPN౷ܭ৘ใϥΠϒϥϦ • 

    SJBL@DPSF෼ࢄγεςϜϑϨʔϜϫʔΫ •  SJBL@LW෼ࢄ,74ͦͷ΋ͷ •  SJBL@QJQFl6/*9QJQFTGPS3JBLz.BQ3FEVDF༻
  16. ˜#BTIP5FDIOPMPHJFT*OD"MM3JHIUT3FTFSWFE  HFUQVUEFMFUFͷ ϦΫΤετॲཧ •  ෳ਺ͷWOPEF΁ͷϦΫΤετΛѻ͏ίʔσΟωʔλ ͕ϦΫΤετͷϋϯυϦϯάΛߦ͏ •  ίʔσΟωʔλ͕શͯͷϨϓϦΧ΁ͷϦΫΤετΛ ࢼΈΔ

    •  ίʔσΟωΠλʔͰෳ਺ͷϦΫΤετͷԠ౴Λ଴ͪɺ Ϩεϙϯεͷௐ੔Λߦ͏ •  HFUͷࡍʹҟͳΔσʔλ͕WOPEF͔Βฦ͖ͬͯͨ৔߹ɺ ݁ՌΛௐ੔ͯ͠ɺσʔλΛॻ͖໭͢ SFBESFQBJS 
  17. ˜#BTIP5FDIOPMPHJFT*OD"MM3JHIUT3FTFSWFE  "OBUPNZPGB3FRVFTU   get(“mybucket/mykey”) Get Coordinator (FSM) client

    Riak hash(“mybucket/mykey”) => 10, 11, 12 Coordinating node Cluster 6 7 8 9 10 11 12 13 14 15 16 The Ring
  18. ˜#BTIP5FDIOPMPHJFT*OD"MM3JHIUT3FTFSWFE  "OBUPNZPGB3FRVFTU   get(“mybucket/mykey”) Get Coordinator (FSM) client

    Riak hash(“mybucket/mykey”) => 10, 11, 12 get(“mybucket/mykey”) Coordinating node Cluster 6 7 8 9 10 11 12 13 14 15 16 The Ring
  19. ˜#BTIP5FDIOPMPHJFT*OD"MM3JHIUT3FTFSWFE  "OBUPNZPGB3FRVFTU   get(“mybucket/mykey”) Get Coordinator (FSM) client

    Riak Coordinating node Cluster 6 7 8 9 10 11 12 13 14 15 16 R=2 v1 v2 v2 The Ring v2 v1 v2
  20. ˜#BTIP5FDIOPMPHJFT*OD"MM3JHIUT3FTFSWFE  3FBE3FQBJS   Get Coordinator (FSM) Riak Coordinating

    node Cluster 6 7 8 9 10 11 12 13 14 15 16 R=2 v1 v2 Stale! The Ring v2 v1 v2
  21. ˜#BTIP5FDIOPMPHJFT*OD"MM3JHIUT3FTFSWFE  .BQ3FEVDF 4FDPOEBSZ*OEFYͷ ϦΫΤετॲཧ •  શσʔλ͕ࢀরͰ͖ΔWOPEFͷ૊Έ߹ΘͤΛબఆ $PWFSBHF ͯ͠ɺͦΕΒશͯʹ໰͍߹ΘͤΔ 

    ͷWOPEF  •  ̏ͭͷϨϓϦΧͷ͏͕ͪ̍ͭࢀর͞ΕΔ •  ϨϓϦΧΛશͯࢀর͢Δ༁Ͱ͸ͳ͍ͷͰɺ $PWFSBHFΛ༻͍ΔॲཧͰ͸ɺSFBESFQBJS͸࣮ߦ͞ Εͳ͍ •  ଟ͘ͷ৔߹ɺશͯͷ෺ཧαʔό΁ͷϦΫΤετͱͳ Δ
  22. ˜#BTIP5FDIOPMPHJFT*OD"MM3JHIUT3FTFSWFE  .BQ3FEVDF 4FDPOEBSZ*OEFYͷ ϦΫΤετॲཧ •  શσʔλ͕ࢀরͰ͖ΔWOPEFͷ૊Έ߹ΘͤΛબఆ $PWFSBHF ͯ͠ɺͦΕΒશͯʹ໰͍߹ΘͤΔ 

    ͷWOPEF  •  ̏ͭͷϨϓϦΧͷ͏͕ͪ̍ͭࢀর͞ΕΔ •  ϨϓϦΧΛશͯࢀর͢Δ༁Ͱ͸ͳ͍ͷͰɺ $PWFSBHFΛ༻͍ΔॲཧͰ͸ɺSFBESFQBJS͸࣮ߦ͞ Εͳ͍ •  ଟ͘ͷ৔߹ɺશͯͷ෺ཧαʔό΁ͷϦΫΤετͱͳ Δ
  23. ˜#BTIP5FDIOPMPHJFT*OD"MM3JHIUT3FTFSWFE  "OBUPNZPGB3FRVFTU   2i(“mybucket”) Coordinator (FSM) client Riak

    coverage() => 1, 4, 7, 10, 13, 16… Coordinating node Cluster 6 7 8 9 10 11 12 13 14 15 16 The Ring
  24. ˜#BTIP5FDIOPMPHJFT*OD"MM3JHIUT3FTFSWFE  "OBUPNZPGB3FRVFTU   2i(“mybucket”) Coordinator (FSM) client Riak

    coverage() => 1, 4, 7, 10, 13, 16… Coordinating node Cluster 6 7 8 9 10 11 12 13 14 15 16 The Ring
  25. ˜#BTIP5FDIOPMPHJFT*OD"MM3JHIUT3FTFSWFE  "OBUPNZPGB3FRVFTU   2i(“mybucket”) Coordinator (FSM) client Riak

    Coordinating node Cluster 6 7 8 9 10 11 12 13 14 15 16 The Ring v0 v38 v1 v54 v7 v9 v41 v9 v81
  26. ˜#BTIP5FDIOPMPHJFT*OD"MM3JHIUT3FTFSWFE  (PTTJQ1SPUPDPM •  ϊʔυؒͰͷ৘ใ఻ୡʹ࢖༻͞ΕΔϓϩτίϧ •  ఆظతʹϥϯμϜʹબఆͨ͠ϊʔυͱ৘ใΛަ׵͢ Δ SJOHσʔλ 

    •  ͢Έ΍͔ʹ৘ใΛ֦ࢄͤ͞Δ͜ͱ͕Ͱ͖Δ •  ඇޮ཰͕෦෼͕͋Γɺ୆਺͕૿͑ͯ͘Δͱݫ͍͠ QMVNUSFFͷಋೖ  
  27. ˜#BTIP5FDIOPMPHJFT*OD"MM3JHIUT3FTFSWFE  #JUDBTL •  -PH4USVDUVSFE)BTI5BCMF •  ௥هܕɾίϯύΫγϣϯ •  ΩʔΛ͢΂ͯϝϞϦ্ʹల։ LFZEJS

     ϊʔυʹอଘͰ͖Δσʔλྔ͕ϝϞϦʹ΋ґଘ •  55-͋Γ •  )JOUpMFΩʔͷҰཡॲཧɺىಈ࣌ͷΩʔಡΈࠐΈΛิॿ •  4FDPOEBSZ*OEFYͷαϙʔτͳ͠
  28. ˜#BTIP5FDIOPMPHJFT*OD"MM3JHIUT3FTFSWFE  .FNPSZ#BDLFOE •  ΦϯϝϞϦͰσʔλΛอ࣋͢Δ •  55- FYQJSF ͋Γ • 

    ϝϞϦ্ݶ஋ NBY@NFNPSZ Λઃఆ͢Δͱઃఆ஋Λ ௒͑ͨࡍʹݹ͍σʔλΛ࡟আ WOPEFຖʹ'*'0 
  29. ˜#BTIP5FDIOPMPHJFT*OD"MM3JHIUT3FTFSWFE  'VMMTZOD3FQMJDBUJPO •  ΫϥελؒͰσʔλશମͷ ಉظΛߦ͏ •  શσʔλΛεΩϟϯͯࠩ͠ ෼ΛWOPEFؒͰૹ৴ • 

    εέδϡʔϥىಈɺόον ىಈͰఆظతʹ࣮ߦ͢Δ •  ಉظॲཧΛ؅ཧ͢Δίʔσ Οωʔλϊʔυ͕֤Ϋϥε λ಺Ͱબग़͞Εɺނো࣌ʹ ͸ࣗಈతʹଞϊʔυ΁੾Γ ସΘΔɻ
  30. ˜#BTIP5FDIOPMPHJFT*OD"MM3JHIUT3FTFSWFE  WT3FEJT •  3FEJT͸ʮΩϟογϡʯͷͨΊͷγεςϜ •  ӬଓԽͷͨΊͷσʔλϕʔεͰ͋Δ3JBLͱ͸ࠜຊత ʹར༻໨త͕ҟͳΔ •  ෼ࢄߏ੒͸ྺ࢙͕ઙ͍

    •  ӬଓԽ͸௥هܕͰ͸ͳ͍ͨΊো֐࣌ʹσΟεΫʹσ ʔλ͕࢒Βͳ͍Մೳੑ͕͋Δ •  ΦϯϝϞϦͰϦονͳσʔλߏ଄Λఏڙ͢ΔͨΊΞ ϓϦέʔγϣϯ͔Β͸ඇৗʹѻ͍΍͍͢