Transcript
Page 1: Cisco: Application clustering with Couchbase – Couchbase Connect 2016

Clint Ricker

Couchbase Application Clustering

Page 2: Cisco: Application clustering with Couchbase – Couchbase Connect 2016

2© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Confidential

• Solutions Architect, Office of the CTO

• SP Video

Me

Page 3: Cisco: Application clustering with Couchbase – Couchbase Connect 2016

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

Page 4: Cisco: Application clustering with Couchbase – Couchbase Connect 2016

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

Page 5: Cisco: Application clustering with Couchbase – Couchbase Connect 2016

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

Page 6: Cisco: Application clustering with Couchbase – Couchbase Connect 2016

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

Page 7: Cisco: Application clustering with Couchbase – Couchbase Connect 2016

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

Page 8: Cisco: Application clustering with Couchbase – Couchbase Connect 2016

8© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Confidential

Global Distributed Lock

Page 9: Cisco: Application clustering with Couchbase – Couchbase Connect 2016

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

Page 10: Cisco: Application clustering with Couchbase – Couchbase Connect 2016

10© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Confidential

Global Distributed Lock

Page 11: Cisco: Application clustering with Couchbase – Couchbase Connect 2016

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;}

Page 12: Cisco: Application clustering with Couchbase – Couchbase Connect 2016

12© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Confidential

Leader Election

Page 13: Cisco: Application clustering with Couchbase – Couchbase Connect 2016

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…

Page 14: Cisco: Application clustering with Couchbase – Couchbase Connect 2016

14© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Confidential

Page 15: Cisco: Application clustering with Couchbase – Couchbase Connect 2016

15© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Confidential

Leader Election

Page 16: Cisco: Application clustering with Couchbase – Couchbase Connect 2016

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;}

Page 17: Cisco: Application clustering with Couchbase – Couchbase Connect 2016

17© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Confidential

Discovery Service

Page 18: Cisco: Application clustering with Couchbase – Couchbase Connect 2016

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…

Page 19: Cisco: Application clustering with Couchbase – Couchbase Connect 2016

19© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Confidential

Advertise

Page 20: Cisco: Application clustering with Couchbase – Couchbase Connect 2016

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

Page 21: Cisco: Application clustering with Couchbase – Couchbase Connect 2016

21© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Confidential

Discovery

Page 22: Cisco: Application clustering with Couchbase – Couchbase Connect 2016

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

Page 23: Cisco: Application clustering with Couchbase – Couchbase Connect 2016

23© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Confidential

Shared Queues

Page 24: Cisco: Application clustering with Couchbase – Couchbase Connect 2016

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…

Page 25: Cisco: Application clustering with Couchbase – Couchbase Connect 2016

25© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Confidential

Shared Queue Add

Page 26: Cisco: Application clustering with Couchbase – Couchbase Connect 2016

26© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Confidential

Shared Queue Read

Page 27: Cisco: Application clustering with Couchbase – Couchbase Connect 2016

27© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Confidential

Transactions

Page 28: Cisco: Application clustering with Couchbase – Couchbase Connect 2016

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…

Page 29: Cisco: Application clustering with Couchbase – Couchbase Connect 2016

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

Page 30: Cisco: Application clustering with Couchbase – Couchbase Connect 2016

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

Page 31: Cisco: Application clustering with Couchbase – Couchbase Connect 2016

Top Related