Reputation: 629
From what i understand in cassandra When a client writes data to single server, it writes to the commit log(append only log with out random seeks).It then puts data into MEMTable this resides in memory. Then acknowledges saying the write is successfull. When MEMTable is full it is flushed to disk as an SSTable(sequential write)
In a multi Node cluster with 2 nodes named (node1,node2). When a client writes data to node1 that is supposed to reside in node2(according to the tokens assigned to the nodes).
Upvotes: 4
Views: 295
Reputation: 9475
The node that a client connects to when it issues a write becomes the coordinator for that write. So in your scenario, node1 would be the coordinator. Node1 would then calculate the token hash value for the write and see that this token is owned by node2. It would then forward the write to node2.
Node2 would receive the write request from node1 and since it is a local write, would add it to the commitlog and memtable on node2. This is so that if node2 were to go down before the memtable is flushed, it can rebuild the memtable by replaying the commitlog.
When the memtable is flushed on node2 it will be saved to disk on node2.
Once the write has finished on node2, it will tell node1 that the write was successful and node1 will then tell the client that the write was successful.
A read works in pretty much the same way. The client issues a read to a node that becomes the coordinator for the read. The coordinator contacts the nodes that own the tokens for the data and they send the results back to the coordinator. The coordinator merges the results based on the latest timestamp and sends the final result back to the client.
Upvotes: 4