Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Cassandra High Availability
Cassandra High Availability

Cassandra High Availability: Harness the power of Apache Cassandra to build scalable, fault-tolerant, and readily available applications

eBook
$9.99 $16.99
Paperback
$26.99
Subscription
Free Trial
Renews at $19.99p/m

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Table of content icon View table of contents Preview book icon Preview Book

Cassandra High Availability

Chapter 2. Data Distribution

Cassandra's peer-to-peer architecture and scalability characteristics are directly tied to its data placement scheme. Cassandra employs a distributed hash table data structure that allows data to be stored and retrieved by a key quickly and efficiently. Consistent hashing is the core of this strategy as it enables all nodes to understand where data exists in the cluster without complicated coordination mechanisms.

In this chapter, we'll cover the following topics:

  • The fundamentals of distributed hash tables
  • Cassandra's consistent hashing mechanism
  • Token assignment, both manual and using virtual nodes (vnodes)
  • The implications of Cassandra's partitioner implementations
  • Formation of hotspots in the cluster

By the time you finish this chapter, you should have a deep understanding of these concepts. Let's begin with some basics about hash tables in general, and then we can delve deeper into Cassandra's distributed hash table implementation...

Hash table fundamentals

Most developers have experience with hash tables in some form, as nearly all programming languages include hash table implementations. Hash tables store data by applying a hash function to the object, which determines its placement in an underlying array.

While a detailed description of hashing algorithms is out of scope of this book, it is sufficient for you to understand that a hash function simply maps any input data object (which might be any size) to some expected output. While the input might be large, the output of the hash function will be a fixed number of bits.

In a typical hash table design, the result of the hash function is divided by the number of array slots; the remainder then becomes the assigned slot number. Thus, the slot can be computed using hash(o) % n, where o is the object and n is the number of slots. Consider the following hash table with names as keys and addresses as values:

Hash table fundamentals

In the preceding diagram, the values in the table on the left represent...

Consistent hashing

To solve the problem of locating a key in a distributed hash table, we use a technique called consistent hashing. Introduced as a term in 1997, consistent hashing was originally used as a means of routing requests among large numbers of web servers. It's easy to see how the Web can benefit from a hash mechanism that allows any node in the network to efficiently determine the location of an object, in spite of the constant shifting of nodes in and out of the network. This is the fundamental objective of consistent hashing.

The mechanics of consistent hashing

With consistent hashing, the buckets are arranged in a ring with a predefined range; the exact range depends on the partitioner being used. Keys are then hashed to produce a value that lies somewhere along the ring. Nodes are assigned a range, which is computed as follows:

Range start

Range end

Token value

Next token value - 1

Note

The following examples assume that the default Murmur3Partitioner is used. For...

Token assignment

In Cassandra terminology, the start of the hash range is called a token, and until version 1.2, each node was assigned a single token in the manner discussed in the previous section. Version 1.2 introduced the option to use vnodes, as the feature is officially termed. vnodes became the default option in the 2.0 release.

Cassandra determines where to place data using the tokens assigned to each node. Nodes learn about these token assignments via gossip. Additional replicas are then placed based on the configured replication strategy and snitch. More details about replica placement can be found in Chapter 3, Replication.

Manually assigned tokens

If you're running a version prior to 1.2 or if you have chosen not to use vnodes, you will have to assign tokens manually. This is accomplished by setting the initial_token in cassandra.yaml.

Manual token assignment introduces a number of potential issues:

  • Adding and removing nodes: When the size of the ring changes, all tokens must...

Partitioners

You might recall from the earlier discussion of distributed hash tables that keys are mapped to nodes via an implementation-specific hash function. In Cassandra's architecture, this function is determined by the partitioner you choose. This is a cluster-wide setting specified in cassandra.yaml. As of version 1.2, there are three options:

  • Murmur3Partitioner: This produces an even distribution of data across the cluster using the MurmurHash algorithm. This is the default as of version 1.2, and should not be changed as it is measurably faster than the RandomPartitioner.
  • RandomPartitioner: This is similar to the Murmur3Partitioner, except that it computes an MD5 hash. This was the default prior to version 1.2.
  • ByteOrderedPartitioner: This places keys in byte order (lexically) around the ring. This partitioner should generally be avoided for reasons explained in this section.

The only reason to switch from the default Murmur3Partitioner to ByteOrderedPartitioner would be to enable...

Summary

At this point, you should have a strong grasp of Cassandra's data distribution architecture, including consistent hashing, tokens, vnodes, and partitioners, as well as some of the causes of data hotspots. Your understanding of these fundamentals will help you to make sound design decisions that enable you to scale your cluster effectively and get the most out of your infrastructure investment.

In this chapter and the previous one, we made reference to replication and its related concepts a number of times. In the next chapter, we'll discuss replication in depth as replication is very important in determining the availability of data.

Left arrow icon Right arrow icon

Description

If you are a developer or DevOps engineer who understands the basics of Cassandra and are ready to take your knowledge to the next level, then this book is for you. An understanding of the essentials of Cassandra is needed.

What you will learn

  • Understand the core architecture of Cassandra that enables highly available applications Use replication and tunable consistency levels to balance consistency, availability, and performance Set up multiple data centers to enable failover, load balancing, and geographic distribution Add capacity to your cluster with zero downtime Take advantage of high availability features in the native driver Create data models that scale well and maximize availability Understand how to avoid common antipatterns Keep your system working well even during failure scenarios

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Dec 29, 2014
Length: 186 pages
Edition : 1st
Language : English
ISBN-13 : 9781783989133
Category :
Tools :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Product Details

Publication date : Dec 29, 2014
Length: 186 pages
Edition : 1st
Language : English
ISBN-13 : 9781783989133
Category :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
$19.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
$199.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts
$279.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total $ 130.97
Mastering Apache Cassandra - Second Edition
$54.99
Cassandra High Availability
$26.99
Learning Apache Cassandra
$48.99
Total $ 130.97 Stars icon
Banner background image

Table of Contents

10 Chapters
1. Cassandra's Approach to High Availability Chevron down icon Chevron up icon
2. Data Distribution Chevron down icon Chevron up icon
3. Replication Chevron down icon Chevron up icon
4. Data Centers Chevron down icon Chevron up icon
5. Scaling Out Chevron down icon Chevron up icon
6. High Availability Features in the Native Java Client Chevron down icon Chevron up icon
7. Modeling for High Availability Chevron down icon Chevron up icon
8. Antipatterns Chevron down icon Chevron up icon
9. Failing Gracefully Chevron down icon Chevron up icon
Index Chevron down icon Chevron up icon

Customer reviews

Top Reviews
Rating distribution
Full star icon Full star icon Full star icon Full star icon Half star icon 4.6
(14 Ratings)
5 star 64.3%
4 star 35.7%
3 star 0%
2 star 0%
1 star 0%
Filter icon Filter
Top Reviews

Filter reviews by




Andreas Baakind Feb 03, 2015
Full star icon Full star icon Full star icon Full star icon Full star icon 5
This book is very useful for those who have just started working with Cassandra and wants to avoid the common mistakes that many developers make. It is also a good starting point for those who have a relational database background since it covers the most common pitfalls these developers make. Cassandra may look like a relational database for the very first time, but it acts quite different under the hood. The author has a good way of describing many of the mistakes we make, and how easy it is to do so. He also brings forth the impact on performance from these mistakes.The book also contains simple examples and explanations of how to successfully model for high performance and availability. It uses some of the most known use cases for Cassandra today to illustrate: time series- and geospatial data.Overall I would recommend this book to developer who just started working with Cassandra, and those who are struggling with performance in an already existing cluster. If you do not have any experience with Cassandra beforehand, you will still benefit from reading this book since it will teach you how to do things right and prevent you from making bad decisions later on.
Amazon Verified review Amazon
Amazon Shopper Mar 02, 2015
Full star icon Full star icon Full star icon Full star icon Full star icon 5
This is the first Cassandra book I can recommend with no reservations. The author has serious hands-on time with Cassandra and it shows in both the level of detail and clarity in describing everything from the big picture down. Including anti-patterns will save new and some experienced Cassandra users a great deal of pain and frustration. A very good book to go along with your first experiences with Apache Cassandra.
Amazon Verified review Amazon
Isidhu Dec 02, 2015
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Perfect as an introduction to Cassandra. Helped streamline the process from dev to production.
Amazon Verified review Amazon
Fabricio Suarte Apr 24, 2015
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Very good book. I found information in that book that I had not found in the internet. The author is very experienced about Cassandra.
Amazon Verified review Amazon
giacomo benelli Apr 20, 2015
Full star icon Full star icon Full star icon Full star icon Full star icon 5
This is a great book, it gets straight to the point and gives you lots of insights about real use cases. I suggest to approach this book after having read the available documentation, in particular the one available on Datastax web site. Don't get me wrong, a total beginner would still benefit from this book, but it's the kind of read where every sentence counts and fundamental concept are present but not repeated over and over. To get the full implications of many concepts, you probably need to have already heard or dealt with them.Also, even though the title is about high availability, a good amount of time is spent on other related concepts such as performance, application design, example of data center design...If you plan to ever use Cassandra seriously, get this book and you will have a solid foundation to get started.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.