Introduction to.ppt_第1页
Introduction to.ppt_第2页
Introduction to.ppt_第3页
Introduction to.ppt_第4页
Introduction to.ppt_第5页
已阅读5页,还剩24页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、Introduction toApache Cassandra,(for Java developers!),Nate McCall zznate,Brief Intro,NOT a key/value store Columns are dynamic inside a column family SSTables are immutable SSTables merged on reads All nodes share the same role (i.e. no single point of failure) Trading ACID compliance for scalabili

2、ty is a fundamental design decision,How does this impact development?,Substantially. For operations affecting the same data, that data will become consistent eventually as determined by the timestamps. But you can trade availability for consistency. (More on this later) You can store whatever you wa

3、nt. Its all just bytes. You need to think about how you will query the data before you write it.,Neat. So Now What?,Like any database, you need a client! Python: Telephus: Pycassa: Java: Hector: Pelops: Kundera Datanucleus JDO: Grails: grails-cassandra: .NET: FluentCassandra: Aquiles: Ruby: Cassandr

4、a: PHP: phpcassa: SimpleCassie:,. but do not roll your own,Thrift,Fast, efficient serialization and network IO. Lots of clients available (you can probably use it in other places as well) Why you dont want to work with the Thrift API directly: SuperColumn ColumnOrSuperColumn ColumnParent.super_colum

5、n ColumnPath.super_column Map mutationMap,Higher Level Client,Hector JMX Counters Add/remove hosts: automatically programatically via JMX Plugable load balancing Complete encapsulation of Thrift API Type-safe approach to dealing with Apache Cassandra Lightweight ORM (supports JPA 1.0 annotations) Ma

6、venized!/maven2/me/prettyprint/,CQL,Currently in Apache Cassandra trunk Experimental Lots of possibilities fromtest/system/test_cql.py: UPDATE StandardLong1 SET 1L=1, 2L=2, 3L=3, 4L=4 WHERE KEY=aa SELECT cd1, col FROM Standard1 WHERE KEY = kd DELETE cd1, col FROM Standard1 WHERE

7、 KEY = kd,Avro?,Gone. Added too much complexity after Thrift caught up. None of the libraries distinguished themselves as being a particularly crappy choice for serialization. (SeeCASSANDRA-1765),Thrift API Methods,Retrieving Writing/Removing Meta Information Schema Manipulation,Thrift API Methods -

8、 Retrieving,get: retrieve a single column for a key get_slice: retrieve a slice of columns for a key multiget_slice: retrieve a slice of columns for a list of keys get_count: counts the columns of key (you have to deserialize the row to do it) get_range_slices: retrieve a slice for a range of keys g

9、et_indexed_slices (FTW!),Thrift API Methods - Writing/Removing,insert batch_mutate (batch insertion AND deletion) remove truncate*,Thrift API Methods - Meta Information,describe_cluster_name describe_version describe_keyspace describe_keyspaces,Thrift API Methods - Schema,system_add_keyspace system_

10、update_keyspace system_drop_keyspace system_add_column_family system_update_column_family system_drop_column_family,vs. RDBMS - Consistency Level,Consistency istunable per request! Cassandra provides consistency when R + W N (read replica count +write replica count replication factor). * CONSITENCY

11、LEVEL FAILURE IS NOT A ROLLBACK* Idempotent: an operation can be applied multiple times without changing the result,vs. RDBMS - Append Only,Proper data modelling will minimizes seeks (Go to Tylers presentation for more!),On to the Code., Uses Maven. Really basic. Modify/abuse/alter as needed. Descri

12、ptions of what is going on and how to run each example are in the Javadoc comments. Sample data is based on North American Numbering Plan /wiki/North_American_Numbering_Plan,Data Shape,512 202 30.27 097.74 W TX Austin 512 203 30.27 097.74 L TX Austin 512 204 30.32 097.73 W TX A

13、ustin 512 205 30.32 097.73 W TX Austin 512 206 30.32 097.73 L TX Austin,Get a Single Column for a Key,GetCityForNpanxx.java Retrieve a single column with: Name Value Timestamp TTL,Get the Contents of a Row,GetSliceForNpanxx.java Retrieves a list of columns (Hector wraps these in a ColumnSlice) Slice

14、Predicate can either be explicit set of columns OR a range (more on ranges soon) Another messy either/or choice encapsulated by Hector,Get the (sorted!) Columns of a Row,GetSliceForStateCity.java Shows why the choice of comparator is important (this is the order in which the columns hit the disk - t

15、ake advantage of it) Can be easily modified to return results in reverse order (but this is slightly slower),Get the Same Slice from Several Rows,MultigetSliceForNpanxx.java Very similar to get_slice examples, except we provide a list of keys,Get Slices From a Range of Rows,GetRangeSlicesForStateCit

16、y.java Like multiget_slice, except we can specify a KeyRange (encapsulated by RangeSlicesQuery#setKeys(start, end) The results of this query will be significantly more meaningful with OrderPreservingPartitioner (try this at home!),Get Slices From a Range of Rows - 2,GetSliceForAreaCodeCity.java Comp

17、ound column name for controlling ranges Comparator at work on text field,Get Slices from Indexed Columns,GetIndexedSlicesForCityState.java You only need to index a single column to apply clauses on other columns (BUT- the indexed column must be present with an EQUALS clause!) (Its just another Colum

18、nFamily maintained automatically),Insert, Update and Delete,. are effectively the same operation. InsertRowsForColumnFamilies.java DeleteRowsForColumnFamily.java Run each in succession (in whichever combination you like) and verify your results on the CLI Hint: watch the timestamps bin/cassandra-cli

19、 -host localhost use Tutorial; list AreaCode; list Npanxx; list StateCity;,Stuff I Punted on for the Sake of Brevity,meta_* methods CassandraClusterTest.java: L43-81 hector system_* methods SchemaManipulation.java hector-examples CassandraClusterTest.java: L84-157 hector ORM (it works and is in production) ORM Documentation multiple nodes failure scenarios Data modelling (go see Tylers presentation),Things to Remember,deletes and timestamp granularity range ghosts u

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论