Nag
Nag

Reputation: 2057

Cassandra - What is guaranteed with respect to the tables

I had two following tables ( taken from Cassandra Definitve Guide , https://gist.github.com/jeffreyscarpenter/761ddcd1c125dfb194dc02d753d31733 } - What is guaranteed with respect to the folloowing tables assuming they had the same partition key ?

  1. Can we safely assume the data for both the tables present in the same node as long as the partition key is same ? as both tables contain same partition key.
  2. Ok , and as tables are different from each other , will they be stored in different partitions or same partition in the "same" node

https://gist.github.com/jeffreyscarpenter/761ddcd1c125dfb194dc02d753d31733

CREATE TABLE hotel.pois_by_hotel (
    poi_name text,
    hotel_id text,
    description text,
    PRIMARY KEY ((hotel_id), poi_name)
) WITH comment = 'Q3. Find pois near a hotel';

CREATE TABLE hotel.available_rooms_by_hotel_date (
    hotel_id text,
    date date,
    room_number smallint,
    is_available boolean,
    PRIMARY KEY ((hotel_id), date, room_number)
) WITH comment = 'Q4. Find available rooms by hotel / date';

Upvotes: 0

Views: 20

Answers (1)

Alex Ott
Alex Ott

Reputation: 87144

  1. if both tables have the same partition key, then the same value will be mapped into the same token. If tables are in the same keyspace, then yes - they will be on the same node(s). If they are in the different keyspaces, then there could be a partial overlap - if replication factor is different, for example, one keyspace has higher RF (like, KS1 has RF=2, and KS2 has RF=3, then 2 nodes will have replicas for both keyspaces, and 3rd node will have only for KS2).
  2. Each table will have its own set of the files on disk, so although they have the same "logical partitions", on disk they are in different files. You can always look into data files, something like, /var/lib/cassandra/data/<keyspace>/<table>-<table-uuid>/

Upvotes: 1

Related Questions