Cassandra Community Webinar: Apache Cassandra Internals

Download Cassandra Community Webinar: Apache Cassandra Internals

Post on 26-Jan-2015




0 download

Embed Size (px)


Apache Cassandra solves many interesting problems to provide a scalable, distributed, fault tolerant database. Cluster wide operations track node membership, direct requests and implement consistency guarantees. At the node level, the Log Structured storage engine provides high performance reads and writes. All of this is implemented in a Java code base that has greatly matured over the past few years. In this webinar Aaron Morton will step through read and write requests, automatic processes and manual maintenance tasks. He will also discuss the general approach to solving the problem and drill down to the code responsible for implementation. Speaker: Aaron Morton, Apache Cassandra Committer Aaron Morton is a Freelance Developer based in New Zealand, and a Committer on the Apache Cassandra project. In 2010 he gave up the RDBMS world for the scale and reliability of Cassandra. He now spends his time advancing the Cassandra project and helping others get the best out of it.


<ul><li> 1. CASSANDRA COMMUNITY WEBINARS AUGUST 2013 CASSANDRA INTERNALS Aaron Morton @aaronmorton Co-Founder &amp; Principal Consultant Licensed under a Creative Commons Attribution-NonCommercial 3.0 New Zealand License </li></ul> <p> 2. AboutThe Last Pickle Work with clients to deliver and improve Apache Cassandra based solutions. Apache Cassandra Committer, DataStax MVP, Hector Maintainer, 6+ years combined Cassandra experience. Based in New Zealand &amp; Austin,TX. 3. Architecture Code 4. Cassandra Architecture API's Cluster Aware Cluster Unaware Clients Disk 5. Cassandra Cluster Architecture API's Cluster Aware Cluster Unaware Clients Disk API's Cluster Aware Cluster Unaware Disk Node 1 Node 2 6. Dynamo Cluster Architecture API's Dynamo Database Clients Disk API's Dynamo Database Disk Node 1 Node 2 7. Architecture API Dynamo Database 8. APITransports Thrift Native Binary 9. ThriftTransport //Custom TServer implementations o.a.c.thrift.CustomTThreadPoolServer o.a.c.thrift.CustomTNonBlockingServer o.a.c.thrift.CustomTHsHaServer 10. APITransports Thrift Native Binary 11. Native BinaryTransport Beta in Cassandra 1.2 Uses Netty Enabled with start_native_transport (Disabled by default) 12. //Setup the Netty server new ExecutionHandler() new NioServerSocketChannelFactory() ServerBootstrap.setPipelineFactory() 13. o.a.c.transport.Message.Dispatcher.messageReceived() //Process message from client ServerConnection.validateNewMessage() Request.execute() ServerConnection.applyStateTransition() Channel.write() 14. Messages Dened in the Native Binary Protocol $SRC/doc/native_protocol.spec 15. API Services JMX Thrift CQL 3 16. JMX Management Beans Spread around the code base. Interfaces named *MBean 17. JMX Management Beans Registered with names such as org.apache.cassandra.db: type=StorageProxy 18. API Services JMX Thrift CQL 3 19. o.a.c.thrift.CassandraServer // Implements Thrift Interface // Access control // Input validation // Mapping to/from Thrift and internal types 20. Thrift Interface Thrift IDL $SRC/interface/cassandra.thrift 21. o.a.c.thrift.CassandraServer.get_slice() // get columns for one row Tracing.begin() ClientState cState = state() cState.hasColumnFamilyAccess() multigetSliceInternal() 22. CassandraServer.multigetSliceInternal() // get columns for may rows ThriftValidation.validate*() // Create ReadCommands getSlice() 23. CassandraServer.getSlice() // Process ReadCommands // return Thrift types readColumnFamily() thriftifyColumnFamily() 24. CassandraServer.readColumnFamily() // Process ReadCommands // Return ColumnFamilies 25. API Services JMX Thrift CQL 3 26. o.a.c.cql3.QueryProcessor // Prepares and executes CQL3 statements // Used by Thrift &amp; Native transports // Access control // Input validation // Returns transport.ResultMessage 27. CQL3 Grammar ANTLR Grammar $SRC/o.a.c.cql3/Cql.g 28. o.a.c.cql3.statements.ParsedStatement // Subclasses generated by ANTLR // Tracks bound term count // Prepare CQLStatement prepare() 29. o.a.c.cql3.statements.CQLStatement checkAccess(ClientState state) validate(ClientState state) execute(ConsistencyLevel cl, QueryState state, List variables) 30. statements.SelectStatement.RawStatement // Implements ParsedStatement // Input validation prepare() 31. statements.SelectStatement.execute() // Create ReadCommands 32. Architecture API Dynamo Database 33. Dynamo Layer o.a.c.service o.a.c.dht o.a.c.gms o.a.c.locator 34. o.a.c.service.StorageProxy // Cluster wide storage operations // Select endpoints &amp; check CL available // Send messages to Stages // Wait for response // Store Hints 35. o.a.c.service.StorageService // Ring operations // Track ring state // Start &amp; stop ring membership // Node &amp; token queries 36. o.a.c.service.IResponseResolver preprocess(MessageIn message) resolve() throws DigestMismatchException RowDigestResolver RowDataResolver RangeSliceResponseResolver 37. Response Handlers / Callback implements IAsyncCallback response(MessageIn msg) 38. o.a.c.service.ReadCallback.get() //Wait for blockfor &amp; data condition.await(timeout, TimeUnit.MILLISECONDS) throw ReadTimeoutException() resolver.resolve() 39. o.a.c.service.StorageProxy.fetchRows() getLiveSortedEndpoints() new RowDigestResolver() new ReadCallback() MessagingService.sendRR() --------------------------------------- ReadCallback.get() # blocking catch (DigestMismatchException ex) catch (ReadTimeoutException ex) 40. Dynamo Layer o.a.c.service o.a.c.dht o.a.c.gms o.a.c.locator 41. MUTATION READ REQUEST_RESPONSE TREE_REQUEST TREE_RESPONSE (And more...) 42. new EnumMap(Verb.class) 43. doVerb(MessageIn message, String id); 44. new EnumMap(MessagingService.Verb.class) 45. runnable = new MessageDeliveryTask( message, id, timestamp); StageManager.getStage( message.getMessageType()); stage.execute(runnable); 46. // If dropable and rpc_timeout MessagingService.incrementDroppedMessag es(verb); MessagingService.getVerbHandler(verb) verbHandler.doVerb(message, id) 47. Architecture API Layer Dynamo Layer Database Layer 48. Database Layer o.a.c.concurrent o.a.c.db o.a.c.cache o.a.c.trace 49. o.a.c.concurrent.StageManager stages = new EnumMap(Stage.class); getStage(Stage stage) 50. o.a.c.concurrent.Stage READ MUTATION GOSSIP REQUEST_RESPONSE ANTI_ENTROPY (And more...) 51. Database Layer o.a.c.concurrent o.a.c.db o.a.c.cache o.a.c.trace 52. o.a.c.db.Table // Keyspace open(String table) getColumnFamilyStore(String cfName) getRow(QueryFilter filter) apply(RowMutation mutation, boolean writeCommitLog) 53. o.a.c.db.ColumnFamilyStore // Column Family getColumnFamily(QueryFilter filter) getTopLevelColumns(...) apply(DecoratedKey key, ColumnFamily columnFamily, SecondaryIndexManager.Updater indexer) 54. o.a.c.db.IColumnContainer addColumn(IColumn column) remove(ByteBuffer columnName) ColumnFamily SuperColumn 55. o.a.c.db.ISortedColumns addColumn(IColumn column, Allocator allocator) removeColumn(ByteBuffer name) ArrayBackedSortedColumns AtomicSortedColumns TreeMapBackedSortedColumns 56. o.a.c.db.Memtable put(DecoratedKey key, ColumnFamily columnFamily, SecondaryIndexManager.Updater indexer) flushAndSignal(CountDownLatch latch, Future context) 57. o.a.c.db.ReadCommand getRow(Table table) SliceByNamesReadCommand SliceFromReadCommand 58. o.a.c.db.IDiskAtomFilter getMemtableColumnIterator(...) getSSTableColumnIterator(...) IdentityQueryFilter NamesQueryFilter SliceQueryFilter 59. Summary CustomTThreadPoolServer Message.Dispatcher CassandraServer QueryProcessor ReadCommand StorageProxy IResponseResolver IAsyncCallback MessagingService IVerbHandler Table ColumnFamilyStore IDiskAtomFilter API Dynamo Database 60. Thanks. 61. Aaron Morton @aaronmorton Co-Founder &amp; Principal Consultant Licensed under a Creative Commons Attribution-NonCommercial 3.0 New Zealand License </p>