I recently started working with Cassandra database. I have installed single node cluster
in my local box. And I am working with Cassandra 1.2.3
.
I was reading the article on the internet and I found this line-
Cassandra writes are first written to a commit log (for durability), and then to an in-memory table structure called a memtable. A write is successful once it is written to the commit log and memory, so there is very minimal disk I/O at the time of write. Writes are batched in memory and periodically written to disk to a persistent table structure called an SSTable (sorted string table).
So to understand the above lines, I wrote a simple program that will write to Cassandra Database using Pelops client
. And I was able to insert the data in Cassandra database.
And now I am trying to see how my data was written into commit log
and where that commit log file
is? And also how SSTables
is generated and where I can find that as well in my local box and what it contains also.
I wanted to see these two files so that I can understand more how Cassandra works behind the scenes.
In my cassandra.yaml file, I have something like this
# directories where Cassandra should store data on disk.
data_file_directories:
- S:\Apache Cassandra\apache-cassandra-1.2.3\storage\data
# commit log
commitlog_directory: S:\Apache Cassandra\apache-cassandra-1.2.3\storage\commitlog
# saved caches
saved_caches_directory: S:\Apache Cassandra\apache-cassandra-1.2.3\storage\savedcaches
But when I opened commitLog, first of all it has lot of data so my notepad++ is not able to open it properly and if it gets opened, I cannot see properly because of some encoding or what. And in my data folder, I cannot find out anything?
Meaning this folder is empty for me-
S:\Apache Cassandra\apache-cassandra-1.2.3\storage\data\my_keyspace\users
Is there anything I am missing here? Can anybody explain me how to read commitLog and SSTables files and where I can find these two files? And also what exactly happens behind the scenes whenever I am writing to Cassandra database.
Updated:-
Code I am using to insert into Cassandra Database-
public class MyPelops {
private static final Logger log = Logger.getLogger(MyPelops.class);
public static void main(String[] args) throws Exception {
// -------------------------------------------------------------
// -- Nodes, Pool, Keyspace, Column Family ---------------------
// -------------------------------------------------------------
// A comma separated List of Nodes
String NODES = "localhost";
// Thrift Connection Pool
String THRIFT_CONNECTION_POOL = "Test Cluster";
// Keyspace
String KEYSPACE = "my_keyspace";
// Column Family
String COLUMN_FAMILY = "users";
// -------------------------------------------------------------
// -- Cluster --------------------------------------------------
// -------------------------------------------------------------
Cluster cluster = new Cluster(NODES, 9160);
Pelops.addPool(THRIFT_CONNECTION_POOL, cluster, KEYSPACE);
// -------------------------------------------------------------
// -- Mutator --------------------------------------------------
// -------------------------------------------------------------
Mutator mutator = Pelops.createMutator(THRIFT_CONNECTION_POOL);
log.info("- Write Column -");
mutator.writeColumn(
COLUMN_FAMILY,
"Row1",
new Column().setName(" Name ".getBytes()).setValue(" Test One ".getBytes()).setTimestamp(new Date().getTime()));
mutator.writeColumn(
COLUMN_FAMILY,
"Row1",
new Column().setName(" Work ".getBytes()).setValue(" Engineer ".getBytes()).setTimestamp(new Date().getTime()));
log.info("- Execute -");
mutator.execute(ConsistencyLevel.ONE);
// -------------------------------------------------------------
// -- Selector -------------------------------------------------
// -------------------------------------------------------------
Selector selector = Pelops.createSelector(THRIFT_CONNECTION_POOL);
int columnCount = selector.getColumnCount(COLUMN_FAMILY, "Row1",
ConsistencyLevel.ONE);
System.out.println("- Column Count = " + columnCount);
List<Column> columnList = selector
.getColumnsFromRow(COLUMN_FAMILY, "Row1",
Selector.newColumnsPredicateAll(true, 10),
ConsistencyLevel.ONE);
System.out.println("- Size of Column List = " + columnList.size());
for (Column column : columnList) {
System.out.println("- Column: (" + new String(column.getName()) + ","
+ new String(column.getValue()) + ")");
}
System.out.println("- All Done. Exit -");
System.exit(0);
}
}
Keyspace and Column family that I have created-
create keyspace my_keyspace with placement_strategy = 'org.apache.cassandra.locator.SimpleStrategy' and strategy_options = {replication_factor:1};
use my_keyspace;
create column family users with column_type = 'Standard' and comparator = 'UTF8Type';