Skip to content

Commit c1e3a63

Browse files
authored
JAVA-2976: Protocol v5 error codes CAS_WRITE_UNKNOWN, CDC_WRITE_FAILURE not supported (4.x) (#1586)
1 parent 71e5757 commit c1e3a63

File tree

5 files changed

+159
-1
lines changed

5 files changed

+159
-1
lines changed

bom/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
<dependency>
7272
<groupId>com.datastax.oss</groupId>
7373
<artifactId>native-protocol</artifactId>
74-
<version>1.5.0</version>
74+
<version>1.5.1</version>
7575
</dependency>
7676
<dependency>
7777
<groupId>com.datastax.oss</groupId>
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/*
2+
* Copyright DataStax, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.datastax.oss.driver.api.core.servererrors;
17+
18+
import com.datastax.oss.driver.api.core.AllNodesFailedException;
19+
import com.datastax.oss.driver.api.core.ConsistencyLevel;
20+
import com.datastax.oss.driver.api.core.DriverException;
21+
import com.datastax.oss.driver.api.core.cql.ExecutionInfo;
22+
import com.datastax.oss.driver.api.core.metadata.Node;
23+
import com.datastax.oss.driver.api.core.retry.RetryPolicy;
24+
import com.datastax.oss.driver.api.core.session.Request;
25+
import edu.umd.cs.findbugs.annotations.NonNull;
26+
27+
/**
28+
* The result of a CAS operation is in an unknown state.
29+
*
30+
* <p>This exception is processed by {@link RetryPolicy#onErrorResponseVerdict(Request,
31+
* CoordinatorException, int)} , which will decide if it is rethrown directly to the client or if
32+
* the request should be retried. If all other tried nodes also fail, this exception will appear in
33+
* the {@link AllNodesFailedException} thrown to the client.
34+
*/
35+
public class CASWriteUnknownException extends QueryConsistencyException {
36+
37+
public CASWriteUnknownException(
38+
@NonNull Node coordinator,
39+
@NonNull ConsistencyLevel consistencyLevel,
40+
int received,
41+
int blockFor) {
42+
this(
43+
coordinator,
44+
String.format(
45+
"CAS operation result is unknown - proposal was not accepted by a quorum. (%d / %d)",
46+
received, blockFor),
47+
consistencyLevel,
48+
received,
49+
blockFor,
50+
null,
51+
false);
52+
}
53+
54+
private CASWriteUnknownException(
55+
@NonNull Node coordinator,
56+
@NonNull String message,
57+
@NonNull ConsistencyLevel consistencyLevel,
58+
int received,
59+
int blockFor,
60+
ExecutionInfo executionInfo,
61+
boolean writableStackTrace) {
62+
super(
63+
coordinator,
64+
message,
65+
consistencyLevel,
66+
received,
67+
blockFor,
68+
executionInfo,
69+
writableStackTrace);
70+
}
71+
72+
@NonNull
73+
@Override
74+
public DriverException copy() {
75+
return new CASWriteUnknownException(
76+
getCoordinator(),
77+
getMessage(),
78+
getConsistencyLevel(),
79+
getReceived(),
80+
getBlockFor(),
81+
getExecutionInfo(),
82+
true);
83+
}
84+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
* Copyright DataStax, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.datastax.oss.driver.api.core.servererrors;
17+
18+
import com.datastax.oss.driver.api.core.AllNodesFailedException;
19+
import com.datastax.oss.driver.api.core.DriverException;
20+
import com.datastax.oss.driver.api.core.cql.ExecutionInfo;
21+
import com.datastax.oss.driver.api.core.metadata.Node;
22+
import com.datastax.oss.driver.api.core.retry.RetryPolicy;
23+
import com.datastax.oss.driver.api.core.session.Request;
24+
import edu.umd.cs.findbugs.annotations.NonNull;
25+
import edu.umd.cs.findbugs.annotations.Nullable;
26+
27+
/**
28+
* An attempt was made to write to a commitlog segment which doesn't support CDC mutations.
29+
*
30+
* <p>This exception is processed by {@link RetryPolicy#onErrorResponseVerdict(Request,
31+
* CoordinatorException, int)}, which will decide if it is rethrown directly to the client or if the
32+
* request should be retried. If all other tried nodes also fail, this exception will appear in the
33+
* {@link AllNodesFailedException} thrown to the client.
34+
*/
35+
public class CDCWriteFailureException extends QueryExecutionException {
36+
37+
public CDCWriteFailureException(@NonNull Node coordinator) {
38+
super(coordinator, "Commitlog does not support CDC mutations", null, false);
39+
}
40+
41+
public CDCWriteFailureException(@NonNull Node coordinator, @NonNull String message) {
42+
super(coordinator, "Commitlog does not support CDC mutations", null, false);
43+
}
44+
45+
private CDCWriteFailureException(
46+
@NonNull Node coordinator,
47+
@NonNull String message,
48+
@Nullable ExecutionInfo executionInfo,
49+
boolean writableStackTrace) {
50+
super(coordinator, message, executionInfo, writableStackTrace);
51+
}
52+
53+
@NonNull
54+
@Override
55+
public DriverException copy() {
56+
return new CDCWriteFailureException(getCoordinator(), getMessage(), getExecutionInfo(), true);
57+
}
58+
}

core/src/main/java/com/datastax/oss/driver/internal/core/cql/Conversions.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040
import com.datastax.oss.driver.api.core.retry.RetryPolicy;
4141
import com.datastax.oss.driver.api.core.servererrors.AlreadyExistsException;
4242
import com.datastax.oss.driver.api.core.servererrors.BootstrappingException;
43+
import com.datastax.oss.driver.api.core.servererrors.CASWriteUnknownException;
44+
import com.datastax.oss.driver.api.core.servererrors.CDCWriteFailureException;
4345
import com.datastax.oss.driver.api.core.servererrors.CoordinatorException;
4446
import com.datastax.oss.driver.api.core.servererrors.FunctionFailureException;
4547
import com.datastax.oss.driver.api.core.servererrors.InvalidConfigurationInQueryException;
@@ -75,6 +77,7 @@
7577
import com.datastax.oss.protocol.internal.response.Error;
7678
import com.datastax.oss.protocol.internal.response.Result;
7779
import com.datastax.oss.protocol.internal.response.error.AlreadyExists;
80+
import com.datastax.oss.protocol.internal.response.error.CASWriteUnknown;
7881
import com.datastax.oss.protocol.internal.response.error.ReadFailure;
7982
import com.datastax.oss.protocol.internal.response.error.ReadTimeout;
8083
import com.datastax.oss.protocol.internal.response.error.Unavailable;
@@ -505,6 +508,15 @@ public static CoordinatorException toThrowable(
505508
context.getWriteTypeRegistry().fromName(writeFailure.writeType),
506509
writeFailure.numFailures,
507510
writeFailure.reasonMap);
511+
case ProtocolConstants.ErrorCode.CDC_WRITE_FAILURE:
512+
return new CDCWriteFailureException(node, errorMessage.message);
513+
case ProtocolConstants.ErrorCode.CAS_WRITE_UNKNOWN:
514+
CASWriteUnknown casFailure = (CASWriteUnknown) errorMessage;
515+
return new CASWriteUnknownException(
516+
node,
517+
context.getConsistencyLevelRegistry().codeToLevel(casFailure.consistencyLevel),
518+
casFailure.received,
519+
casFailure.blockFor);
508520
case ProtocolConstants.ErrorCode.SYNTAX_ERROR:
509521
return new SyntaxError(node, errorMessage.message);
510522
case ProtocolConstants.ErrorCode.UNAUTHORIZED:

core/src/main/java/com/datastax/oss/driver/internal/core/util/ProtocolUtils.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@ public static String errorCodeString(int errorCode) {
9595
return "FUNCTION_FAILURE";
9696
case ProtocolConstants.ErrorCode.WRITE_FAILURE:
9797
return "WRITE_FAILURE";
98+
case ProtocolConstants.ErrorCode.CDC_WRITE_FAILURE:
99+
return "CDC_WRITE_FAILURE";
100+
case ProtocolConstants.ErrorCode.CAS_WRITE_UNKNOWN:
101+
return "CAS_WRITE_UNKNOWN";
98102
case ProtocolConstants.ErrorCode.SYNTAX_ERROR:
99103
return "SYNTAX_ERROR";
100104
case ProtocolConstants.ErrorCode.UNAUTHORIZED:

0 commit comments

Comments
 (0)