Clint Ricker
Couchbase Application Clustering
2© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Confidential
• Solutions Architect, Office of the CTO
• SP Video
Me
3© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Confidential
• Shipping Couchbase in service provider grade software since 2012
• Running in mission critical, very large scale on-prem and AAS offerings around the world
• Datasets of billions of records
Cisco / Couchbase
4© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Confidential
• Creating a clustered application glued together by Couchbase
• Use Couchbase / lightweight code snippets instead of common datacenter technologies
• Replacing Zookeeper, Eureka, Consul, Rabbit/HornetMQ, etc…
What
5© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Confidential
What
App Instance
App Instance
App Instance
Couchbase
App Instance
App Instance
App Instance
Couchbase Shared Storage
Dependent Databases
Zookeeper
Consul
RabbitMQ
Load Balancer Load Balancer
6© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Confidential
• Complexity kills • Lower machine count• Organizational needs• Application needs• Love of roll your own• Very minimal feature set
Why
7© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Confidential
• More application code to maintain• Schema changes are difficult• Existing platform stack • Less sensitivity to deployment
footprint• Very minimal feature set
Why not
8© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Confidential
Global Distributed Lock
9© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Confidential
Global Distributed Lock
• Used to ensure certain activities are globally serialized
• Typically provided by Consul / Zookeeper / etc
10© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Confidential
Global Distributed Lock
11© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Confidential
Global Distributed Lockuint64_t CBGetLock(char *lockKey, int objectLockTimeout) {
if (status == CBSTATUS_SUCCESS) { for (i = 0; i < retries; i++) { status = CBObjGet(buf, &cas, lockKey,objectLockTimeout); if (status >= 0) { return cas; } } } return CBSTATUS_FAILURE;}
12© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Confidential
Leader Election
13© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Confidential
Leader Election
• Used to have a dynamically dedicated master instance for ongoing activity
• Common for frequent maintenance needs
• Typically provided by Consul, Zookeeper, etc…
14© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Confidential
15© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Confidential
Leader Election
16© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Confidential
Leader Electionuint64_t CBElectMasterPrivate(char *masterKey, int ttl, uint64_t masterKeyCas) {
if (masterKeyCas > 0) { status = CBObjReplace(masterKey, "master", masterKeyCas, ttl); } else { status = CBObjSet(masterKey, "master", masterKeyCas, ttl); }
if (status == CBSTATUS_SUCCESS) { for (i = 0; i < retries; i++) { status = CBObjGet(buf, &cas, masterKey, NOLOCK); if (status >= 0) { return cas; } } CBObjDeleteCas(masterKey, cas); return CBSTATUS_FAILURE; } return CBSTATUS_FAILURE;}
17© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Confidential
Discovery Service
18© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Confidential
Discovery Service
• Used to discover endpoints for specific services or the total set of nodes in the cluster
• Supports basic load balancing and health check
• Often provided by Consul, Eureka, DNS, etc…
19© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Confidential
Advertise
20© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Confidential
<NodeList><Node>
<NodeName>appInstance1</NodeName><Updated>2016-10-24T12:23:42Z</Updated><Address>172.31.31.15:80</Address>
</Node></NodeList><NodeList>
<Node><NodeName>appInstance2</NodeName><Updated>2016-10-24T12:23:41Z</Updated><Address>172.17.126.2:80</Address>
</Node></NodeList>
Example
21© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Confidential
Discovery
22© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Confidential
Discovery
Couchbase
App2 Service Instance
App2 Service Instance
App2 Service Instance
App1 Service Instance
Advertise “foo”, “instance ip address”
Lookup “foo”, choose instance Send request to address of selected instance
23© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Confidential
Shared Queues
24© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Confidential
Shared Queues
• Create shared queues that are polled by set of nodes
• Typically provided by HornetQ, RabbitMQ, etc…
25© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Confidential
Shared Queue Add
26© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Confidential
Shared Queue Read
27© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Confidential
Transactions
28© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Confidential
Transactions
• Create a generic globally shared transaction system with rollback
• Typically provided by HornetQ, RabbitMQ, etc…
29© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Confidential
Transactions
App1 Service InstanceIncoming request
App2 Service Instance
App2 Service Instance
App1 Service InstanceApp1 Service Instance
LB
Service requestw/callback URL
Service requestw/callback URL
Callback
Callback
30© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Confidential
If transaction failed or timed out
1
2
Create Transaction
Transaction State Record w/state=active and time=currentTime
Transaction Log Record
1
2
4
Close Transaction
Delete Transaction State Record
Delete Transaction Log
1
2
3
RollbackEither synchronously with failure or discovered through query of transaction state records
Pull transaction log
Iterate through transaction log in reverse
Undo each activity
1
2
3
Transactions
Update Transaction state record with state=active and time=currentTime
Append Activity to Transaction Log Record
1
2
Execute Activity