[
https://issues.apache.org/jira/browse/CASSJAVA-116?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18034978#comment-18034978
]
Bret McGuire commented on CASSJAVA-116:
---------------------------------------
Worth noting that we only specify an Astra request ID generator [in case one
isn't provided via SessionBuilder|
[https://github.com/apache/cassandra-java-driver/blob/4.19.1/core/src/main/java/com/datastax/oss/driver/api/core/session/SessionBuilder.java#L878-L885]
] so a short-term workaround would be for users to just specify their own
request ID generator. It's not great but if somebody needs something right
away it'll work:
{code:java}
private static class MyRequestIdGenerator extends W3CContextRequestIdGenerator {
public MyRequestIdGenerator(String payloadKey) {
super(payloadKey);
}
@Override
public Statement<?> getDecoratedStatement(Statement<?> statement, String
requestId) {
NullAllowingImmutableMap.Builder<String, ByteBuffer> builder =
NullAllowingImmutableMap.<String, ByteBuffer>builder();
for (Map.Entry<String, ByteBuffer> entry :
statement.getCustomPayload().entrySet()) {
if (!entry.getKey().equals(getCustomPayloadKey()))
builder.put(entry.getKey(), entry.getValue());
}
builder.put(getCustomPayloadKey(),
ByteBuffer.wrap(requestId.getBytes(StandardCharsets.UTF_8)));
return statement.setCustomPayload(builder.build());
}
@Override
public String getCustomPayloadKey() {
return super.getCustomPayloadKey();
}
}
...
try (CqlSession session = CqlSession.builder()
.withCloudSecureConnectBundle(Paths.get(props.get(SCB_PATH).toString()))
.withAuthCredentials("token", props.get(ASTRA_TOKEN).toString())
.withKeyspace(props.get(ASTRA_KEYSPACE).toString())
.withRequestIdGenerator(idGenerator)
.build()) { {code}
I reproduced the error locally with a test client and then confirmed that the
change above addresses the issue.
> Retry or Speculative Execution with RequestIdGenerator throws "Duplicate Key"
> -----------------------------------------------------------------------------
>
> Key: CASSJAVA-116
> URL: https://issues.apache.org/jira/browse/CASSJAVA-116
> Project: Apache Cassandra Java driver
> Issue Type: Improvement
> Components: Core
> Reporter: Jane He
> Assignee: Jane He
> Priority: Urgent
> Time Spent: 10m
> Remaining Estimate: 0h
>
> Exception looks something like the following:
>
> {code:java}
> java.lang.IllegalArgumentException: Duplicate key traceparent
> at
> com.datastax.oss.protocol.internal.util.collection.NullAllowingImmutableMap$Builder.failIfDuplicateKeys(NullAllowingImmutableMap.java:226)
> ~[native-protocol-1.5.2.jar:?]
> at
> com.datastax.oss.protocol.internal.util.collection.NullAllowingImmutableMap$Builder.build(NullAllowingImmutableMap.java:198)
> ~[native-protocol-1.5.2.jar:?]
> at
> com.datastax.oss.driver.api.core.tracker.RequestIdGenerator.getDecoratedStatement(RequestIdGenerator.java:74)
> ~[java-driver-core-4.19.1.jar:4.19.1]
> at
> com.datastax.oss.driver.internal.core.cql.CqlRequestHandler.lambda$sendRequest$3(CqlRequestHandler.java:291)
> ~[java-driver-core-4.19.1.jar:4.19.1] {code}
>
> It's because CqlRequestHandler can call {{sendRequest}} more than one time,
> so "getDecoreatedStatement" can be called more than one time, so there will
> be duplicate key.
> We should modify the {{RequestIdGenerator.getDecoratedStatement}} so that
>
> {code:java}
> if (statement.getCustomPayload().containsKey(getCustomPayloadKey()))
> { return statement; }
>
> {code}
>
> This is a serious bug, we should release the fix ASAP.
>
>
--
This message was sent by Atlassian Jira
(v8.20.10#820010)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]