I am reading about Cassandra and how other databases maintain the wal and memtable.
WAL - As name suggests, cassandra writes all mutations sequentially in this file
My question is - if there are thousands of parallel requests coming to the same node of cassandra, how does it maintain sequential writes to WAL.
I check cassandra code base and I could not find any thread lock or anything mutex operation.
Cassandra write code
private CommitLogPosition addToCommitLog(Mutation mutation)
{
// Usually one of these will be true, so first check if that's the case.
boolean allSkipCommitlog = true;
boolean noneSkipCommitlog = true;
for (PartitionUpdate update : mutation.getPartitionUpdates())
{
if (update.metadata().params.memtable.factory().writesShouldSkipCommitLog())
noneSkipCommitlog = false;
else
allSkipCommitlog = false;
}
if (!noneSkipCommitlog)
{
if (allSkipCommitlog)
return null;
else
{
Set<TableId> ids = new HashSet<>();
for (PartitionUpdate update : mutation.getPartitionUpdates())
{
if (update.metadata().params.memtable.factory().writesShouldSkipCommitLog())
ids.add(update.metadata().id);
}
mutation = mutation.without(ids);
}
}
// Note: It may be a good idea to precalculate none/all for the set of all tables in the keyspace,
// or memoize the mutation.getTableIds()->ids map (needs invalidation on schema version change).
Tracing.trace("Appending to commitlog");
return CommitLog.instance.add(mutation); --- ** Actual commit log write ***
}
Any help would be appreciated.