Your SlideShare is downloading. ×
0
Introduction to Apache Cassandra and support within WSO2 Platform<br />Srinath Perera<br />WSO2 Inc.<br />
Cassandra within the WSO2 Platform<br />We support Apache Cassandra within WSO2 Platform<br />This is to provide NoSQL dat...
What is Cassandra? <br />Apache Cassandra http://cassandra.apache.org/<br />NoSQL column family implementation (more about...
Column Family Data Model<br />Column – name, value, and a timestamp (ignore this for now). Column is bit of a misnomer, ma...
Column Family Data Model (Contd.)<br />It is crucial to understand that Cassandra Columns are very different from RDBMS Co...
OK?? How can I do something useful withthis?<br />
Example: Book Rating Site<br />Let us take a Book rating site as an example. Users add books, comment them and tag them. <...
Relational Approach<br />Schema <br />Books(bookid, author, rank, price, link) <br />Comments->(id, text, user, time, book...
Cassandra Approach<br />Schema<br />Books[BookID->(author, rank, price, link, tag1, tag2 ..) ] <br />Tags2Books[TagID->(ti...
Potential Solution [Contd.]<br />Handling Queries <br />
Some Queries You Can Not Do<br />Above setup can do some queries it designed for. <br />It can not queries it can not desi...
A Sample Program<br />Cluster cluster = HFactory.createCluster("TestCluster",<br />			    new CassandraHostConfigurator("l...
Cassandra: How does it work?<br />Nodes are arranged in a circle according to a key space(P2P networkand uses consistent h...
Cassandra: How does it work? (Contd.)<br />Writes are written to enough nodes, and Cassandra repairs data while reading. (...
All these are great, but what is the catch?<br />Do not get me wrong, Cassandra is a great tool, but you have to know wher...
Surprises if you are using Cassandra<br />No transactions, no JOINs. Hope there is no surprise here. <br />No foreign keys...
Surprises if you are using Cassandra (Cont.)<br />Failed Operations may  leave changes <br />If operation is successful, a...
Cassandra within WSO2 Platform<br />
Cassandra within the WSO2 Platform<br />As a part of WSO2 data solutions <br />Because one storage cannot handle all cases...
Apache Cassandra as a Service<br />Users can log in to the  Web Console (both in Stratos and in WSO Data Server) and creat...
Apache Cassandra as a Service (Contd.) <br />Key spaces <br />will be allocated from a Cassandra cluster<br />they are iso...
A sample Program<br />Map<String, String> credentials = new HashMap<String, String>();<br />credentials.put(USERNAME_KEY, ...
Implementation<br />
Implementation (Contd.) <br />Cassandra includes a plug point to add support for different security models at the server (...
Cassandra within Carbon Platform<br />Users may choose to run Carbon enabled Cassandra also in two other alternative setti...
Demo<br />
Summary<br />We discuss what Cassandra is, its strength, weaknesses, and Column Family Data Model. <br />Has a data model ...
References<br />Apache Cassandra <br />http://cassandra.apache.org<br />Understanding Column family Model - http://arin.me...
Questions?<br />
Upcoming SlideShare
Loading in...5
×

Introduction to Apache Cassandra and support within WSO2 Platform

7,236

Published on

Published in: Education, Technology
1 Comment
3 Likes
Statistics
Notes
  • Please help how can achieve multitenancy in cassandra
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
No Downloads
Views
Total Views
7,236
On Slideshare
0
From Embeds
0
Number of Embeds
29
Actions
Shares
0
Downloads
120
Comments
1
Likes
3
Embeds 0
No embeds

No notes for slide

Transcript of "Introduction to Apache Cassandra and support within WSO2 Platform"

  1. 1. Introduction to Apache Cassandra and support within WSO2 Platform<br />Srinath Perera<br />WSO2 Inc.<br />
  2. 2. Cassandra within the WSO2 Platform<br />We support Apache Cassandra within WSO2 Platform<br />This is to provide NoSQL data support within the platform<br />Cassandra can be used for both Column family or Key-value pair usecases. <br />Fully integrated with the Platform<br />We will discuss what this means. <br />
  3. 3. What is Cassandra? <br />Apache Cassandra http://cassandra.apache.org/<br />NoSQL column family implementation (more about it later)<br />Highly scalable, available and no Single Point of Failure.<br />Very high write throughput and good read throughput. It is pretty fast. <br />SQL like query language (from 0.8) and support search through secondary indexes (well no JOINs, Group By etc. ..). <br />Tunable consistency and support replication<br />Flexible Schema <br />
  4. 4. Column Family Data Model<br />Column – name, value, and a timestamp (ignore this for now). Column is bit of a misnomer, may be they should have called it a named cell. <br />E.g. author=“Asimov” . <br />Row – row is a collection of Columns with a name. entries are sorted by the column names. You can do a slice and get some of the columns only. <br />E.g. “Second Foundation”->{author=“Asmiov”, publishedDate=“..”,<br /> tag=“sci-fi”, tag2=“asimov” }<br />Column family – Collection of rows, usually no sort order among rows*. <br />Books->{<br /> “Foundation”->{author=“Asmiov”, publishedDate=“..”},<br />“Second Foundation”->{author=“Asmiov”, publishedDate=“..”},<br />…..<br />}<br />There are other stuff, but these are the key. <br />
  5. 5. Column Family Data Model (Contd.)<br />It is crucial to understand that Cassandra Columns are very different from RDBMS Columns. <br />Columns are only applied within a given row, different row may have different columns. <br />You can have thousands to millions of column for a row (2 million max, and a row should fit in one node).<br />Column names may represent data, not just metadata like with RDBMS. <br />You will understand more with the example. <br />
  6. 6. OK?? How can I do something useful withthis?<br />
  7. 7. Example: Book Rating Site<br />Let us take a Book rating site as an example. Users add books, comment them and tag them. <br />Can Add books (author, rank, price, link)<br />Can add Comments for books (text, time, name)<br />Can add tags for books<br />Need to list books sorted by rank<br />Need to list books by tag <br />Need to list comments for a book <br />
  8. 8. Relational Approach<br />Schema <br />Books(bookid, author, rank, price, link) <br />Comments->(id, text, user, time, bookid) <br />Tags(id, bookid, tag)<br />Queries <br />Select * from Books orderby rank;<br />Select text, time, user from Comments where bookid=? Orderby time<br />Select tag from Tags where bookid=?<br />Select bookid from Tags where tag=“”<br />Select distinct author from Tags, Books where Tags.bookid=Books.bookidand tag=?<br />
  9. 9. Cassandra Approach<br />Schema<br />Books[BookID->(author, rank, price, link, tag1, tag2 ..) ] <br />Tags2Books[TagID->(timestamp1=bookID1, timestamp2=bookID2, ..) ] <br />Tags2Authors[TagID->(timestamp1=bookID1, timestamp2=bookID2, ..) ]<br />Comments[BookID-> (timestamp1= text + “-” + author …)]<br />Ranks[“RANK” -> (rank=bookID)] <br />Example data snapshot<br />
  10. 10. Potential Solution [Contd.]<br />Handling Queries <br />
  11. 11. Some Queries You Can Not Do<br />Above setup can do some queries it designed for. <br />It can not queries it can not designed for<br />For example, it can not do following<br />Select * from Books where price > 50; <br />Select * from Books where author=“Asimov”<br />Select * from Books, Comments where rank> 9 && Comments.bookid=Books.bookid;<br />Well it can, but by writing code to walk through. It is like supporting search by going through all the data. <br />This is a limitation, specially when queries are provided at the runtime. <br />
  12. 12. A Sample Program<br />Cluster cluster = HFactory.createCluster("TestCluster",<br /> new CassandraHostConfigurator("localhost:9160”));<br />Keyspacekeyspace = HFactory.createKeyspace(keyspaceName, cluster);<br />Mutator<String> mutator = HFactory.createMutator(keyspace, sser);<br />mutator.insert(“wso2”, columnFamily, <br />HFactory.createStringColumn("address", ”4131 El Camino Real Suite 200, Palo Alto, CA 94306"));<br />ColumnQuery<String, String, String> columnQuery =<br />HFactory.createStringColumnQuery(keyspace);<br />columnQuery.setColumnFamily(columnFamily).setKey(”wso2”).setName("address");<br />QueryResult<HColumn<String, String>> result = columnQuery.execute();<br />System.out.println("received "+ result.get().getName() + "= " <br />+ result.get().getValue() + " ts = "+ result.get().getClock());<br />
  13. 13. Cassandra: How does it work?<br />Nodes are arranged in a circle according to a key space(P2P networkand uses consistent hashing). <br />Each node owns the next clockwise address space.<br />If replicated, each node owns next two clockwise address spaces. <br />Any node can accept any request and route it to the correct node. <br />
  14. 14. Cassandra: How does it work? (Contd.)<br />Writes are written to enough nodes, and Cassandra repairs data while reading. (As you would guess, that is how writes are fast.)<br />Data is updated in the memory, and it keeps an append only commit log to recover from failures. (This avoid rotational latency at the disk). Can do about 80-360MB/sec per node. <br />When ever a read happens, Cassandra will sync all the nodes having replicas (read repair). <br />
  15. 15. All these are great, but what is the catch?<br />Do not get me wrong, Cassandra is a great tool, but you have to know where it does not work.<br />
  16. 16. Surprises if you are using Cassandra<br />No transactions, no JOINs. Hope there is no surprise here. <br />No foreign keys, and keys are immutable. (well no JOINs, and use surrogate keys if you need to change keys)<br />Keys has to be unique (use composite keys)<br />Super Columns and order preserving partitioner are discouraged.<br />Searching is complicated <br />No Search coming from the core. Secondary indexes are layered on top, and they do not do range search or pattern search. <br />When secondary indexes does not work, have to learn the data model and build your indexes using sort orders and slices. <br />Sort orders are complicated<br />Column are always sorted by name, but row order depends on the partitioner. Sort orders are crucial when you build your own indexes. <br />
  17. 17. Surprises if you are using Cassandra (Cont.)<br />Failed Operations may leave changes <br />If operation is successful, all is well<br />If it failed, actually changes may have been applied. But operations are idempotent, so you can retry until successful. <br />Batch operations are not atomic, but you can retry until successful (as operations are idempotent). <br />If a node fails, Cassandra does not figure it out and do a self healing. Assuming you have replicas, things will continue to work. But the whole system recovers only when a manual recover operation is done. <br />It remembers deletes <br />When we delete a data item, a node may be down at the time and may come back after the delete is done. To avoid this, Cassandra mark the as deleted (Tombstones) but does not delete this until configurable timeout or a repair. Space is actually freed up only then. <br />
  18. 18. Cassandra within WSO2 Platform<br />
  19. 19. Cassandra within the WSO2 Platform<br />As a part of WSO2 data solutions <br />Because one storage cannot handle all cases<br />Specifically for applications that need to scale. For applications that can work with a single DB, we have “Database as a Service”<br />Two offerings<br />Provide Cassandra as a Service<br />Provide Cassandra within Carbon as a standalone product (integrated with WSO2 security model)<br />
  20. 20. Apache Cassandra as a Service<br />Users can log in to the Web Console (both in Stratos and in WSO Data Server) and create Cassandra key spaces. <br />
  21. 21. Apache Cassandra as a Service (Contd.) <br />Key spaces <br />will be allocated from a Cassandra cluster<br />they are isolated from other tenants in Stratos<br />it is integrated with WSO2 Security model. <br />Users can manage and share his key spaces through Stratos Web Console and use those key spaces through Hector Client (Java Client for Cassandra)<br />In essence we provide <br />Cassandra as a part of Stratos as a Service<br />Multi-tenancy support<br />Security integration with WSO2 security model<br />
  22. 22. A sample Program<br />Map<String, String> credentials = new HashMap<String, String>();<br />credentials.put(USERNAME_KEY, "admin@srinath.org");<br />credentials.put(PASSWORD_KEY, "admin1234");<br />Cluster cluster = HFactory.createCluster("TestCluster",<br /> new CassandraHostConfigurator("localhost:9160”, credentials));<br />Keyspacekeyspace = HFactory.createKeyspace(keyspaceName, cluster);<br />Mutator<String> mutator = HFactory.createMutator(keyspace, sser);<br />mutator.insert(“wso2”, columnFamily, <br />HFactory.createStringColumn("address", ”4131 El Camino Real Suite 200, Palo Alto, CA 94306"));<br />ColumnQuery<String, String, String> columnQuery =<br />HFactory.createStringColumnQuery(keyspace);<br />columnQuery.setColumnFamily(columnFamily).setKey(”wso2”).setName("address");<br />QueryResult<HColumn<String, String>> result = columnQuery.execute();<br />System.out.println("received "+ result.get().getName() + "= " <br /> + result.get().getValue() + " ts = "+ result.get().getClock());<br />
  23. 23. Implementation<br />
  24. 24. Implementation (Contd.) <br />Cassandra includes a plug point to add support for different security models at the server (Authentication and authorization for server). <br />We do security integration and support isolation among tenants (multi-tenancy) by writing new implementation of this plug point.<br />Also we provide a Web console to manage Cassandra Key spaces. <br />Cassandra is highly scalable and highly available, so no work needed at that department. <br />
  25. 25. Cassandra within Carbon Platform<br />Users may choose to run Carbon enabled Cassandra also in two other alternative settings. <br />Running whole Stratos within a private Cloud<br />Gets full support for the Multi-tenancy and other cloud benefits <br /> Let user run it in his own controlled environment <br />Running a standalone Cassandra node (without Multi-tenancy)<br />Get seamless integration with WSO2 Security model <br />Use the Configuration Console for Cassandra<br />
  26. 26. Demo<br />
  27. 27. Summary<br />We discuss what Cassandra is, its strength, weaknesses, and Column Family Data Model. <br />Has a data model very different from relational style <br />Need users to rethink their data model<br />There is a complexity at design, which is a tradeoff for achieving higher scalability. <br />Of course, Cassandra is not the solution for everything. It should be used when it make sense based on the usecase. <br />We discuss Cassandra integration to WSO2 platform <br />Carbon integration – how to run Cassandra that is integrated with WSO2 Carbon platform security model. <br />Cassandra as a Service – how to use Cassandra as a Service from WSO2 Stratos Platform as a Service offering. <br />
  28. 28. References<br />Apache Cassandra <br />http://cassandra.apache.org<br />Understanding Column family Model - http://arin.me/blog/wtf-is-a-supercolumn-cassandra-data-model<br />Hector Client <br />http://github.com/rantav/hector<br />http://prettyprint.me/2010/08/06/hector-api-v2/<br /> Some Theory<br />Malae, N., Cassandra--A Decentralized Structured Storage System<br />Chang, F. and Dean, J. and Ghemawat, S. and Hsieh, W.C. and Wallach, D.A. and Burrows, M. and Chandra, T. and Fikes, A. and Gruber, R.E., Bigtable: A distributed storage system for structured data, ACM Transactions on Computer Systems (TOCS), 2008<br />
  29. 29. Questions?<br />
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×