如何将Scylla DB中的计数器列重置为零?



是否可以在Scylla DB中重置计数器列?

Cassandra中,不可能直接将计数器列重置为零:

There is no operation that will allow resetting the counter value. You need to read the value and decrement it using that value.
Be aware that this operation might not be successful since the counter can be changed between your "reset" operations.

对于Scylla DB也是如此吗?

Scylla也有类似的行为。不能将计数器值重置为0,计数器只能递增或递减。

scylla@cqlsh:ks> CREATE TABLE cf (pk int PRIMARY KEY, my_counter counter);
scylla@cqlsh:ks> UPDATE cf SET my_counter = my_counter + 3 WHERE pk = 0;
scylla@cqlsh:ks> SELECT * FROM cf;
pk | my_counter
----+------------
0 |          3
(1 rows)
scylla@cqlsh:ks> UPDATE cf SET my_counter = 0  WHERE pk = 0;
InvalidRequest: Error from server: code=2200 [Invalid query] message="Cannot set the value of counter column my_counter (counters can only be incremented/decremented, not set)"
scylla@cqlsh:ks> UPDATE cf SET my_counter = my_counter - 3 WHERE pk = 0;
scylla@cqlsh:ks> SELECT * FROM cf;
pk | my_counter
----+------------
0 |          0
(1 rows)

请注意,当尝试直接设置值时出现错误。

更多信息:

https://docs.scylladb.com/using-scylla/counters/scylla-counters

https://docs.scylladb.com/getting-started/types/计数器https://www.scylladb.com/2017/04/04/counters/

最新更新