CQL for Cassandra 2.0

Trace reads at different consistency levels

After performing the setup steps, run and trace queries that read data at different consistency levels. The tracing output shows that using three replicas on a five-node cluster, a consistency level of ONE processes responses from one of three replicas, QUORUM from two of three replicas, and ALL from three of three replicas.

Procedure

  1. Connect cqlsh to the first node in the ring.
    $ ccm node1 cqlsh
  2. On the cqlsh command line, create a keyspace that specifies using three replicas for data distribution in the cluster.
    cqlsh> CREATE KEYSPACE demo_cl WITH replication = {'class':'SimpleStrategy', 'replication_factor':3};
  3. In the three-replica keyspace, create a table, and insert some values:
    cqlsh> USE demo_cl;
    cqlsh:demo_cl> CREATE TABLE demo_table ( id int PRIMARY KEY, col1 int, col2 int );
    cqlsh:demo_cl> INSERT INTO demo_table (id, col1, col2) VALUES (0, 0, 0);
  4. Turn on tracing and use the CONSISTENCY command to check that the consistency level is ONE, the default.
    cqlsh:demo_cl> TRACING on;
    cqlsh:demo_cl> CONSISTENCY;
    
    The output should be:
    Current consistency level is ONE.
  5. Query the table to read the value of the primary key.
    cqlsh:demo_cl> SELECT * FROM demo_table WHERE id = 0;
    The output includes tracing information:
    id | col1 | col2
    ---+------+------
     0 |    0 |    0
    
    (1 rows)
    
    Tracing session: 230a0d10-5576-11e3-add5-a180b5ee3938
    
     activity                                                                  | timestamp    | source    | source_elapsed
    ---------------------------------------------------------------------------+--------------+-----------+----------------
                                                            execute_cql3_query | 12:13:49,513 | 127.0.0.1 |              0
                    Parsing SELECT * FROM demo_table WHERE id = 0 LIMIT 10000; | 12:13:49,514 | 127.0.0.1 |            540
                                                           Preparing statement | 12:13:49,515 | 127.0.0.1 |           1206
                                                 Sending message to /127.0.0.3 | 12:13:49,515 | 127.0.0.1 |           1768
                                                 Sending message to /127.0.0.4 | 12:13:49,515 | 127.0.0.1 |           1830
                                              Message received from /127.0.0.1 | 12:13:49,517 | 127.0.0.3 |             61
                                              Message received from /127.0.0.1 | 12:13:49,517 | 127.0.0.4 |             66
                                Executing single-partition query on demo_table | 12:13:49,518 | 127.0.0.3 |            793
                                Executing single-partition query on demo_table | 12:13:49,518 | 127.0.0.4 |            914
                                                  Acquiring sstable references | 12:13:49,518 | 127.0.0.3 |            823
                                                  Acquiring sstable references | 12:13:49,518 | 127.0.0.4 |            975
                                                   Merging memtable tombstones | 12:13:49,518 | 127.0.0.3 |            977
                                                   Merging memtable tombstones | 12:13:49,518 | 127.0.0.4 |           1125
     Skipped 0/0 non-slice-intersecting sstables, included 0 due to tombstones | 12:13:49,518 | 127.0.0.3 |           1059
     Skipped 0/0 non-slice-intersecting sstables, included 0 due to tombstones | 12:13:49,518 | 127.0.0.4 |           1203
                                    Merging data from memtables and 0 sstables | 12:13:49,518 | 127.0.0.3 |           1082
                                    Merging data from memtables and 0 sstables | 12:13:49,518 | 127.0.0.4 |           1225
                                            Read 1 live and 0 tombstoned cells | 12:13:49,518 | 127.0.0.3 |           1273
                                              Enqueuing response to /127.0.0.1 | 12:13:49,519 | 127.0.0.3 |           1485
                                            Read 1 live and 0 tombstoned cells | 12:13:49,519 | 127.0.0.4 |           1406
                                                 Sending message to /127.0.0.1 | 12:13:49,519 | 127.0.0.3 |           1711
                                              Enqueuing response to /127.0.0.1 | 12:13:49,519 | 127.0.0.4 |           1628
                                                 Sending message to /127.0.0.1 | 12:13:49,519 | 127.0.0.4 |           1899
                                              Message received from /127.0.0.3 | 12:13:49,520 | 127.0.0.1 |           7003
                                              Message received from /127.0.0.4 | 12:13:49,520 | 127.0.0.1 |           7008
                                           Processing response from /127.0.0.3 | 12:13:49,521 | 127.0.0.1 |           7379
                                           Processing response from /127.0.0.4 | 12:13:49,521 | 127.0.0.1 |           7413
                                                              Request complete | 12:13:49,521 | 127.0.0.1 |           8088
  6. Change the consistency level to QUORUM and run the SELECT statement again.
    cqlsh:demo_cl> CONSISTENCY quorum;
    cqlsh:demo_cl> SELECT * FROM demo_table WHERE id = 0;
    . . .
    Tracing session: 298af000-5576-11e3-add5-a180b5ee3938
    
                                                            execute_cql3_query | 12:19:12,038 | 127.0.0.1 |              0
                    Parsing SELECT * FROM demo_table WHERE id = 0 LIMIT 10000; | 12:19:12,038 | 127.0.0.1 |             88
                                                           Preparing statement | 12:19:12,038 | 127.0.0.1 |            408
                                                 Sending message to /127.0.0.3 | 12:19:12,039 | 127.0.0.1 |           1210
                                                 Sending message to /127.0.0.4 | 12:19:12,039 | 127.0.0.1 |           1230
                                              Message received from /127.0.0.1 | 12:19:12,040 | 127.0.0.3 |             66
                                              Message received from /127.0.0.1 | 12:19:12,040 | 127.0.0.4 |             53
                                Executing single-partition query on demo_table | 12:19:12,040 | 127.0.0.3 |            760
                                Executing single-partition query on demo_table | 12:19:12,040 | 127.0.0.4 |            745
                                                  Acquiring sstable references | 12:19:12,040 | 127.0.0.3 |            790
                                                  Acquiring sstable references | 12:19:12,040 | 127.0.0.4 |            774
                                                   Merging memtable tombstones | 12:19:12,041 | 127.0.0.3 |            875
                                                   Merging memtable tombstones | 12:19:12,041 | 127.0.0.4 |            895
     Skipped 0/0 non-slice-intersecting sstables, included 0 due to tombstones | 12:19:12,041 | 127.0.0.3 |            979
     Skipped 0/0 non-slice-intersecting sstables, included 0 due to tombstones | 12:19:12,041 | 127.0.0.4 |           1022
                                    Merging data from memtables and 0 sstables | 12:19:12,041 | 127.0.0.3 |           1017
                                    Merging data from memtables and 0 sstables | 12:19:12,041 | 127.0.0.4 |           1068
                                            Read 1 live and 0 tombstoned cells | 12:19:12,041 | 127.0.0.3 |           1187
                                            Read 1 live and 0 tombstoned cells | 12:19:12,041 | 127.0.0.4 |           1231
                                              Enqueuing response to /127.0.0.1 | 12:19:12,041 | 127.0.0.3 |           1468
                                              Enqueuing response to /127.0.0.1 | 12:19:12,041 | 127.0.0.4 |           1714
                                                 Sending message to /127.0.0.1 | 12:19:12,042 | 127.0.0.3 |           2025
                                                 Sending message to /127.0.0.1 | 12:19:12,042 | 127.0.0.4 |           2253
                                              Message received from /127.0.0.3 | 12:19:12,042 | 127.0.0.1 |           4326
                                              Message received from /127.0.0.4 | 12:19:12,042 | 127.0.0.1 |           4343
                                           Processing response from /127.0.0.3 | 12:19:12,043 | 127.0.0.1 |           4519
                                           Processing response from /127.0.0.4 | 12:19:12,043 | 127.0.0.1 |           4537
                                                              Request complete | 12:19:12,043 | 127.0.0.1 |           5168
  7. Change the consistency level to ALL and run the SELECT statement again.
    cqlsh:demo_cl> CONSISTENCY ALL;
    cqlsh:demo_cl> SELECT * FROM demo_table WHERE id = 0;
    . . .
    Tracing session: 32733600-5576-11e3-add5-a180b5ee3938
    
     activity                                                                  | timestamp    | source    | source_elapsed
    ---------------------------------------------------------------------------+--------------+-----------+----------------
                                                            execute_cql3_query | 12:20:37,404 | 127.0.0.1 |              0
                    Parsing SELECT * FROM demo_table WHERE id = 0 LIMIT 10000; | 12:20:37,404 | 127.0.0.1 |             88
                                                           Preparing statement | 12:20:37,405 | 127.0.0.1 |            418
                                                 Sending message to /127.0.0.3 | 12:20:37,406 | 127.0.0.1 |           2055
                                                 Sending message to /127.0.0.4 | 12:20:37,406 | 127.0.0.1 |           2076
                                                 Sending message to /127.0.0.5 | 12:20:37,406 | 127.0.0.1 |           2101
                                              Message received from /127.0.0.1 | 12:20:37,407 | 127.0.0.3 |             46
                                              Message received from /127.0.0.1 | 12:20:37,407 | 127.0.0.5 |             57
                                Executing single-partition query on demo_table | 12:20:37,407 | 127.0.0.3 |            554
                                Executing single-partition query on demo_table | 12:20:37,407 | 127.0.0.5 |            547
                                                  Acquiring sstable references | 12:20:37,407 | 127.0.0.3 |            575
                                                  Acquiring sstable references | 12:20:37,407 | 127.0.0.5 |            572
                                                   Merging memtable tombstones | 12:20:37,407 | 127.0.0.3 |            634
                                                   Merging memtable tombstones | 12:20:37,407 | 127.0.0.5 |            645
     Skipped 0/0 non-slice-intersecting sstables, included 0 due to tombstones | 12:20:37,407 | 127.0.0.3 |            719
     Skipped 0/0 non-slice-intersecting sstables, included 0 due to tombstones | 12:20:37,407 | 127.0.0.5 |            745
                                    Merging data from memtables and 0 sstables | 12:20:37,407 | 127.0.0.3 |            757
                                    Merging data from memtables and 0 sstables | 12:20:37,407 | 127.0.0.5 |            778
                                            Read 1 live and 0 tombstoned cells | 12:20:37,408 | 127.0.0.3 |            886
                                            Read 1 live and 0 tombstoned cells | 12:20:37,408 | 127.0.0.5 |            960
                                              Enqueuing response to /127.0.0.1 | 12:20:37,408 | 127.0.0.3 |           1148
                                              Enqueuing response to /127.0.0.1 | 12:20:37,408 | 127.0.0.5 |           1318
                                                 Sending message to /127.0.0.1 | 12:20:37,408 | 127.0.0.3 |           1352
                                                 Sending message to /127.0.0.1 | 12:20:37,408 | 127.0.0.5 |           1702
                                              Enqueuing response to /127.0.0.1 | 12:20:37,409 | 127.0.0.4 |           2530
                                              Message received from /127.0.0.3 | 12:20:37,409 | 127.0.0.1 |           4449
                                              Message received from /127.0.0.5 | 12:20:37,409 | 127.0.0.1 |           4609
                                                 Sending message to /127.0.0.1 | 12:20:37,410 | 127.0.0.4 |           3274
                                           Processing response from /127.0.0.3 | 12:20:37,410 | 127.0.0.1 |           5326
                                           Processing response from /127.0.0.5 | 12:20:37,410 | 127.0.0.1 |           5411
                                              Message received from /127.0.0.4 | 12:20:37,410 | 127.0.0.1 |           6311
                                           Processing response from /127.0.0.4 | 12:20:37,411 | 127.0.0.1 |           6933
                                                              Request complete | 12:20:37,411 | 127.0.0.1 |           7658
Show/hide