You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We should add a configuration option on the connections when they are being added/edited to allow users to decide which time to use.
Add an option to choose desktop time or server time as the time option.
We will need to update the CQLSH code to add this extra option. Expose it as a connection option and add it to our cqlshrc file
from cassandra.cluster import Cluster
# Create a Cluster instance with server-side timestamps
cluster = Cluster(['127.0.0.1'], timestamp_generator=None)
# Create a session
session = cluster.connect()
# Execute queries without client-side timestamps
session.execute("INSERT INTO my_table (id, value) VALUES (1, 'example')")
By default, the Python Cassandra driver uses the MonotonicTimestampGenerator to generate client-side timestamps for write operations. This generator ensures that timestamps are monotonically increasing, even if the system clock drifts backward or if multiple writes occur in rapid succession.
Details of the Default Behavior
MonotonicTimestampGenerator:
This is the default timestamp generator for the Python Cassandra driver.
It generates timestamps in microseconds based on the system clock (time.time()), ensuring that they are always increasing.
If the system clock moves backward or multiple requests are made within a very short time, it artificially increments timestamps to maintain monotonicity.
It also logs warnings if significant clock drift is detected.
Why Client-Side Timestamps Are Default:
Client-side timestamps ensure predictable ordering of operations from the perspective of the client application.
This avoids issues caused by potential clock skew between Cassandra nodes in a distributed system, where server-assigned timestamps may not always reflect the actual order of operations.
Configuration:
You can explicitly configure or replace the default timestamp generator when creating a Cluster instance. For example:
When you do an insert into cassandra using the Python driver it by default uses the driver time as the time.
You can also tell it use the Cassandra server time as the default time. This is managed via how the CQLSH cluster connection is instantiated:
https://github.com/axonops/axonops-workbench-cqlsh/blob/ae3fa132b55187419c4f6f2f763d443d363b8e95/cqlsh/cqlshlib/cqlshmain.py#L415
We should add a configuration option on the connections when they are being added/edited to allow users to decide which time to use.
Add an option to choose desktop time or server time as the time option.
We will need to update the CQLSH code to add this extra option. Expose it as a connection option and add it to our cqlshrc file
By default, the Python Cassandra driver uses the
MonotonicTimestampGenerator
to generate client-side timestamps for write operations. This generator ensures that timestamps are monotonically increasing, even if the system clock drifts backward or if multiple writes occur in rapid succession.Details of the Default Behavior
MonotonicTimestampGenerator:
time.time()
), ensuring that they are always increasing.Why Client-Side Timestamps Are Default:
Configuration:
Cluster
instance. For example:If you want to disable this behavior and use server-side timestamps, set
timestamp_generator=None
when initializing theCluster
instance.Citations:
[1] https://datastax.github.io/cpp-driver/api/struct.CassTimestampGen/
[2] https://docs.datastax.com/en/developer/python-driver/3.8/api/cassandra/timestamps/index.html
[3] https://stackoverflow.com/questions/22759843/python-cassandra-cql-insert-timestamp-and-blob
[4] https://groups.google.com/a/lists.datastax.com/g/python-driver-user/c/6MgM8mCzeZQ
[5] https://docs.datastax.com/en/datastax-drivers/developing/query-timestamps.html
[6] https://datastax-oss.atlassian.net/browse/NODEJS-322
[7] https://datastax-oss.atlassian.net/browse/JAVA-467
[8] https://python-driver.docs.scylladb.com/stable/api/cassandra/cqlengine/query.html
[9] https://packagehub.suse.com/packages/python-cassandra-driver/3_20_2-bp152_1_8/
[10] https://datastax.github.io/python-driver/_modules/cassandra/cluster.html
The text was updated successfully, but these errors were encountered: