Download presentation
Presentation is loading. Please wait.
1
The NoSQL Column Store used by Facebook
Cassandra The NoSQL Column Store used by Facebook
2
Outline Introduction Why Cassandra? Data Model Partition strategy
Membership Replication Strategy Consistency Storage Mechanism CQL Conclusion
3
Apache Cassandra is a highly scalable, high-performance distributed database designed to handle large amounts of data across many servers, providing high availability with no single point of failure. It was originally developed by Facebook to store simple format data such as inbox , it also sets Google BigTable data model and Amazon Dynamo's fully distributed architecture in one. Cassandra's name comes from the Greek mythology, the name of a female prophet of Troy Introduction
4
Timeline Cassandra was developed at Facebook for inbox search.
It was open-sourced by Facebook in July 2008. Cassandra was accepted into Apache Incubator in March 2009. It was made an Apache top-level project since February 2010.
5
Why Cassandra?
6
Scalability, availability, and fault-tolerant.
01 Column-oriented database. 02 Popular, it is being used by Facebook, Twitter, Cisco, Rackspace, Ebay, and more. 03 Faster, more efficiency than relational database management systems. 04 Why Cassandra?
7
Why Cassandra?
8
Data model Column : - Column is the bottom and smallest of the data increment, which is a triple tuple containing the name, value, and timestamp. - Column in Cassandra is a column is a ‘key-value pair’.
9
Data model Describe in Json { name: "course",
{ name: "course", value: "web information", timestamp: }
10
Cols map<byte,columns>
Data model Column Family(CF) Column Family (CF) is a set of Colum of a specific key , which is a row structure type Each CF is physically stored in a separate file, similar to the table in relational database. SuperColum - The ‘value’ of super column is a map containing multiple column and it does not have the timestamps Super column Name:byte Cols map<byte,columns>
11
Data model Describe in Json { // SuperColumn name: "student",
// any number of Column value: { major: {name: "major", value: "computer science", timestamp: }, hometown: {name: "hometown", value: "wellinton", timestamp: }, age: {name: "age", value: "31", timestamp: }, }
12
Data model SuperColum Family
Similar with the CF it is the set of super column KeySpace KeySpace is the outermost container for data in Cassandra.
13
Data model Insert data into column family
Insert data into super column family
14
Data model Cluster
15
Partition strategy Basic Strategy
One of the key design features for Cassandra is the ability to scale incrementally. This requires, the ability to dynamically partition the data over the set of nodes in the cluster. Basic Strategy - The key-value pairs will be stored on different nodes in accordance with the key
16
Partition strategy Partitioner
- Is responsible for allocating data in the cluster, and determines which nodes to place the replicas. Token - Each node has a unique Token to indicates the range of data that the node allocates. Token ring - Partitioner allocates a token to each node according to a certain policy, and each key-value pair will be assigned to the corresponding node on the device.
17
Partition strategy Partition policies RandomPartitioner
- The key -value pair in accordance with the key’s md5 value stored in - the various nodes This policy does not support query for Key’ range. ByteOrderedPartitioner(BOP) - After sorted by the key(byte), the key / value stored in the various - nodes The Partitioner allows the users to scan the data in the order of key.
18
Membership Membership between nodes
Cluster membership in Cassandra is based on Scuttlebutt, a very efficient anti-entropy Gossip based mechanism. Features of Scuttlebutt Efficient CPU utilization and efficient utilization of the gossip channel. Gossip is not only used for membership but also to disseminate other system related control state.
19
Membership-Failure Detection
(1) A node can determine if any other node in the system is up or down. (2) Failure detection can avoid to communicate with unreachable nodes during various operations. Failure detection method Accrual Failure Detection will return a suspicion level for each of monitored nodes, This value is defined as Φ. Every node in the system maintains a sliding window of inter-arrival times of gossip messages from other nodes in the cluster. System will calculate the Φ according to the inter-arrival times
20
Replication Strategy Basic
Cassandra uses replication to achieve high availability and durability. The general data to write N replicas, one of which is written in its corresponding node (determined by the data fragmentation strategy), the other N-1 how to store, the need for a corresponding backup strategy
21
Replication Strategy SimpleStrategy(RackUnawareStrategy)
The coordinator choose n-1 non-coordinator replicas and allocates to the node. The Token in accordance with the order from small to large, from the first Token location in turn take N nodes as a copy. OldNetworkTopologyStrategy(RackAware) Store N-1 data on different racks in the data center where the primary Token is located, and then store a piece of data at another node in a different data center NetworkTopologyStrategy(DatacenterAware) Define the number of data replicas(M) in every datacenter, copy the M replicas to other datacenters and the n-m-1 in the same data center Cassandra will request the zookeeper for a Leeder node , the leader node will provide the rang of the replicas when node joins the cluster Zookeeper is a software that provides consistent services for distributed applications. copy a replica in the zookeeper , Replication Strategy
22
Consistency Cassandra adopts final consistency,which refers to the fact that multiple replicas of a data object in a distributed system may not be consistent in a short period of time, but after a period of time these replicas will be consistent eventually Assume that the number of backup nodes for this data object is n W+R>N is strong consistency W+R<=N weak consistency Features The users can specify the consistence level
23
Consistency Consistency levlel
ZERO: The node responsible for performing the operation sends the modification to all the backup nodes, but does not wait for any node to reply to confirm, this level cannot guarantee the consistency. only meaningful for insert or delete operations.
24
Consistency ONE: For the insert or delete operations, the execution node guarantees that the modification has been written to the’ commit log’ and ‘Memtable of a storage node’; For the read operation, the execution node returns the result immediately after obtaining the data on a storage node.
25
Consistency ALL: for the insert or delete operation, returning the confirmation message to clients after the success of the n nodes inserted or deleted If any node is not successful, the operation failed; for the read operation, query n nodes and return the timestamp of the latest data same as other operations, if any node does not return data, then that read failed.
26
Consistency QUORUM:. For insert or delete operations, guaranteed to write to at least n / storage nodes; for read operations, query to n / storage nodes and return timestamps for the latest data. QUORUM is the default mode, which ensures the every reading operation can receive the latest modification
27
Storage mechanism CommitLog
before writing data, Cassandra also needs to record the log, called Commit Log MenTable MemTable is a memory structure, when the amount of data full the block size, the bulk will be flushed to disk SSTable sstable is a storage formal in the hard disk ,and once thedata is written , it cannot be modified, so it can be saw a ‘read-only’ file . Only sequential, no random written.
28
Storage mechanism sstable Data Column family Men table sstable sstable
29
Storage mechanism Due to reduce the redundant SSTable scan, Cassandra uses the BloomFilter, that is, through a number of hash function key mapping to a bitmap, to quickly determine the key which SSTable. Bloom filter − These are nothing but quick, nondeterministic, algorithms for testing whether an element is a member of a set. It is a special kind of cache. Bloom filters are accessed after every query.
30
Storage mechanism To reduce the consumption as the huge amount of sstable, Cassandra has a compaction mechanism to combine the redundant sstable into a new sstable. Responsibility of compaction
31
Storage mechanism Rubbish Recycle
- Cassandra does not delete data directly, so which leads to huge - disk space consumption, compaction will delete the data marked - as deleted Combine the sstable Generate MerkleTree - The MerkleTreewill be generated in the process of combination, - to compare and modify the primary node and other node .
32
CQL Cassandra does not support the structure query language, and it has a certain language , ‘CQL’(Cassandra query language) The Cassandra Query Language (CQL) is the primary language for communicating with the Apache Cassandra™ database. The most basic way to interact with Apache Cassandra is using the CQL shell, cqlsh. In , you can create keyspaces and tables, insert and query tables, plus much more.
33
CQL-KeySpace Create KeySpace
The CREATE KEYSPACE statement has two properties: replication and durable_writes.
34
CQL-KeySpace Strategy name - Which replication strategy you set
- How many replication factors you want to set Durable_writes. - Boolean value , by default is ture, but you can set is as a - ‘false value’
35
CQL-KeySpace Alter Keyspace
ALTER KEYSPACE can be used to alter properties such as the number of replicas and the durable_writes of a KeySpace. Eg:
36
CQL-KeySpace Drop Keyspace
Using the command DROP KEYSPACE to drop a KeySpace Eg DROP keyspace University drop keyspace university
37
CQL-table Create table
Using the command CREATE TABLE to create a table The primary key is a column that is used to uniquely identify a row. ,defining a primary key is mandatory while creating a table or
38
CQL-table Alter table Using the command ALTER TABLE to alter a table ,such as Add a column and Drop a column Adding a Column When you add a column , you have to ensure the adding name is not conflicting to the existing column names Eg:
39
CQL-column Delete a Column Eg:
40
CQL-column Drop table Using the command Drop Table to drop a table Eg:
41
CQL-column Truncating a Table
Using the TRUNCATE command to truncate a table . When you truncate a table, all the rows of the table are deleted permanently Eg: TRUNCATE course
42
CQL-truncate After truncate
43
CQL-data Inserting Data
using the commandINSERT to insert data into the columns of a row in a Table Eg:
44
CQL-data Updating table Using the command Update Table to drop a table
45
CQL-data Reading data SELECT clause is used to read data from a table in Cassandra. Using this clause, you can read a whole table, a single column, or a particular cell. Eg:
46
CQL-data Using the command DELETE to delete data from a table
Deletes an entire row from a table.
47
CQL-data Deleting a column
48
Conclusion: Cassandra VS Relational Database
the columns are not defined ,filexible, can freely add a column at any time. A schema in a relational model is fixed. a table contains columns, or can be defined as a super column family. table defines only columns and the user fills in the table with values. Supports very simple query language. Supports powerful query language. No fixed schema. It has a fixed schema. It is only “eventually consistent”. Follows ACID (Atomicity, Consistency, Isolation, and Durability). Does not support transactions. Supports transactions.
49
Thank you !
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.