How to achieve insertion of several tables in Kassandra, unique and atomic?

I have a data model in which a domain object has two fields that must be unique and the object must be received through both independently of each other. One of them is randomly generated, so we cannot assume possible collisions. Another is selected by the user. Here is what I came up with:

CREATE TABLE object_primary (
    generated_value text PRIMARY KEY,
    data blob
);

CREATE TABLE object_unique_index (
    user_value text PRIMARY KEY,
    generated_value text
);

Here I use object_unique_index both the index in the primary table and the resource lock, where the resource is a user-selected globally unique value.

First thoughts:

  • The insert in object_unique_index should use IF NOT EXISTS. Therefore, I can not use the package.
  • object_primary , . TIMESTAMP s, .
  • , .
  • , .
  • , .
  • (, ) .

, , . , , , .

UnavailableException: , , . , , ? , ? , , ?

CassandraWriteTimeoutException: , . , UnavailableException. - , ?

:

.

[...]

, ,

, ? , - ( ) ( )?

, , , , ?

+4
2

tl; dr

, - , . , , , , , , .

  • , , .
  • ANY .
  • , , , IF NOT EXISTS.
  • , , , 2,
  • .

.

0

DataStax Cassandra, , , , .

, .

, . (CAS), IF NOT EXISTS . .

Cassandra 1.2 , , , . , , : , .

, , , ( ), (-).

. ( .)

( CAS) - , . , , , object_unique_index ; unique_user_value_for_insert. " " - , ; - IF NOT EXISTS. ( , .)

INSERT user_value, generated_value INTO unique_user_value_for_insert IF NOT EXISTS;

, [applied]=false, , . [applied]=true, .

CAS , , "" . .

UnavailableException

, , UnavailableException. , , , , , , , .

, , node . true, CAS , , , , . ( CAS) , "" CAS.

DELETE , CL.ANY, , / , , , . , .

CassandraWriteTimeoutException

- , , .... [T] , , ( CQL) ( / ).

, , , . , , . -, CAS :

paxos , WriteTimeoutException WriteType.CAS, WriteTimeoutException # getWriteType(). , CAS, , . , . paxos UnavailableException, . , SERIAL LOCAL_SERIAL.

, , . " , CAS", IF NOT EXISTS . , , ; - , . IF NOT EXISTS , :

  • CAS .
  • , [applied]=false].

, , - . "" CAS, (), , .

, CAS :

Cassandra , UnavailableException WriteTimeoutException, . , CAS, , setConsistencyLevel (ConsistencyLevel.SERIAL) , , Cassandra Paxos, . , , SERIAL- CAS, , ​​ CAS.

, "" , Paxos, :

- , , (. WriteTimeoutException # getWriteType()):
 

  BATCH_LOG: -, , . , . , , . , , , , .

  BATCH: , . , Cassandra , , . , , - , havent . , -, , , , , .

  UNLOGGED_BATCH: - , . , , , , . , .

.

. :

  • , , , .
  • , , , IF NOT EXISTS. .
  • , . , , ( ) , - "" , .
  • .
+4

Source: https://habr.com/ru/post/1624482/


All Articles