Book Image

Cassandra High Performance Cookbook

By : Edward Capriolo
Book Image

Cassandra High Performance Cookbook

By: Edward Capriolo

Overview of this book

<p>Apache Cassandra is a fault-tolerant, distributed data store which offers linear scalability allowing it to be a storage platform for large high volume websites. <br /><br />This book provides detailed recipes that describe how to use the features of Cassandra and improve its performance. Recipes cover topics ranging from setting up Cassandra for the first time to complex multiple data center installations. The recipe format presents the information in a concise actionable form.<br /><br />The book describes in detail how features of Cassandra can be tuned and what the possible effects of tuning can be. Recipes include how to access data stored in Cassandra and use third party tools to help you out. The book also describes how to monitor and do capacity planning to ensure it is performing at a high level. Towards the end, it takes you through the use of libraries and third party applications with Cassandra and Cassandra integration with Hadoop.</p>
Table of Contents (20 chapters)
Cassandra High Performance Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Using range scans to find and remove old data


The primary operations used in Cassandra are get and insert operations. In many applications, data can become stale and is no longer needed. In these type of application, a process can be used to iterate all the data on the node using range scans. This recipe shows how to use range scans to iterate all the data in a cluster and remove data older than a user-supplied number of seconds.

How to do it...

  1. Create a file <hpcbuild>/src/hpcas/c03/Ranger.java.

    package hpcas.c03;
    
    import hpcas.c03.FramedConnWrapper;
    import hpcas.c03.Util;
    import java.math.BigInteger;
    import java.util.*;
    import org.apache.cassandra.thrift.*;
    import org.apache.cassandra.utils.FBUtilities;
    public class Ranger {
      int size = 0;
      Cassandra.Client client = null;
      FramedConnWrapper fcw = null;
    
      /*The maximum token in a Cassandra is 2^127. Range scans should not go past 
      this number.*/
      java.math.BigInteger max = new java.math.BigInteger("2").pow(127);
      java.math.BigInteger...