You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by "Robert Stupp (JIRA)" <ji...@apache.org> on 2015/05/13 09:56:01 UTC

[jira] [Commented] (CASSANDRA-9200) Sequences

    [ https://issues.apache.org/jira/browse/CASSANDRA-9200?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14541556#comment-14541556 ] 

Robert Stupp commented on CASSANDRA-9200:
-----------------------------------------

The linked branch contains an implementation of sequences. The code is still ugly but works including utests.

Syntax is explained in {{CQL.textile}} like this:

{code}
<create-sequence-stmt> ::= CREATE ( OR REPLACE )? SEQUENCE ( IF NOT EXISTS )?
                         ( <keyspace> '.' )? <sequencename>
                         ( INCREMENT ( BY )? <integer> )?
                         ( ( MINVALUE <integer> ) | ( NO MINVALUE ) )?
                         ( ( MAXVALUE <integer> ) | ( NO MAXVALUE ) )?
                         ( START ( WITH )? <integer> )?
                         ( CACHE <integer> )?
                         ( CACHE LOCAL <integer> )?
                         ( SERIAL CONSISTENCY LEVEL <consistencyLevel> )?
                         ( CONSISTENCY LEVEL <consistencyLevel> )?
{code}

Access to sequences:
{code}
SELECT nextval('keyspace_name', 'sequence_name') FROM table;
{code}


The implementation uses three tables:
# {{system.schema_sequences}} holding the sequence definitions
# {{system_distributed.seq_reservations}}  tracking the next available sequence value
# {{system.sequence_local}} tracking the range of values exclusively assigned to a node

Notes:
* {{CACHE}} defines the number of values to acquire from the overall range ({{system_distributed.seq_reservations}}).
* {{CACHE LOCAL}} (defaults to {{CACHE}}) defines the number of values to take from {{system.sequence_local}} - not sure whether to keep that option. It's not really necessary and its only limited use is when a node crashes without being gracefully shut down.
* the consistency levels are those used to read from/modify {{system_distributed.seq_reservations}}
* I've not included a {{CYCLE}} option. Reason for that is that it would require a global synchronization of all nodes to ensure that no node still owns a range before wrapping around.
* It also has some limited support for permissions (CASSANDRA-9372).
* {{SELECT nextval}} would benefit from virtual tables (CASSANDRA-7622) - i.e. {{SELECT nextval(...) FROM DUAL}}
* Implementation of {{nextval()}} function requires to pass constant values to function arguments (sneaked into the branch)


> Sequences
> ---------
>
>                 Key: CASSANDRA-9200
>                 URL: https://issues.apache.org/jira/browse/CASSANDRA-9200
>             Project: Cassandra
>          Issue Type: New Feature
>            Reporter: Jonathan Ellis
>            Assignee: Robert Stupp
>             Fix For: 3.x
>
>
> UUIDs are usually the right choice for surrogate keys, but sometimes application constraints dictate an increasing numeric value.
> We could do this by using LWT to reserve "blocks" of the sequence for each member of the cluster, which would eliminate paxos contention at the cost of not being strictly increasing.
> PostgreSQL syntax: http://www.postgresql.org/docs/9.4/static/sql-createsequence.html



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)