Skip to content

Missing LWT routing for batch statements #488

@Bouncheck

Description

@Bouncheck

The following test modified to use batch statement fails with both Scylla 6.2.0 and 5.4.0:

public void should_use_only_one_node_when_lwt_detected() {
    assumeTrue(CcmBridge.SCYLLA_ENABLEMENT); // Functionality only available in Scylla
    CqlSession session = SESSION_RULE.session();
    int pk = 1234;
    ByteBuffer routingKey = TypeCodecs.INT.encodePrimitive(pk, ProtocolVersion.DEFAULT);
    TokenMap tokenMap = SESSION_RULE.session().getMetadata().getTokenMap().get();
    Node owner = tokenMap.getReplicas(session.getKeyspace().get(), routingKey).iterator().next();
    PreparedStatement statement =
        SESSION_RULE
            .session()
            .prepare("INSERT INTO foo (pk, ck, v) VALUES (?, ?, ?) IF NOT EXISTS");

    assertThat(statement.isLWT()).isTrue();
    for (int i = 0; i < 30; i++) {
      BatchStatementBuilder batchStatementBuilder = new BatchStatementBuilder(BatchType.LOGGED);
      batchStatementBuilder.addStatement(statement.bind(pk, i, 123));
      ResultSet result = session.execute(batchStatementBuilder.build());
      assertThat(result.getExecutionInfo().getCoordinator()).isEqualTo(owner);
    }
  }

This batch statement is not seen by the driver as LWT and routes it to the other nodes, likely in the same manner as any other regular query.
If it's possible the driver should treat this example as LWT and in general if it's not possible (e.g. if driver allows multiple LWT statements with different PK's in a batch) then should throw or warn.

Related core issue: https://github.com/scylladb/scylla-enterprise/issues/5331

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions