Skip to content

Commit 83967fd

Browse files
authored
JAVA-2976: Protocol v5 error codes CAS_WRITE_UNKNOWN, CDC_WRITE_FAILURE not supported (3.x) (#1585)
1 parent 6aa2487 commit 83967fd

File tree

4 files changed

+166
-0
lines changed

4 files changed

+166
-0
lines changed

driver-core/src/main/java/com/datastax/driver/core/ExceptionCode.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ enum ExceptionCode {
3636
READ_FAILURE(0x1300),
3737
FUNCTION_FAILURE(0x1400),
3838
WRITE_FAILURE(0x1500),
39+
CDC_WRITE_FAILURE(0x1600),
40+
CAS_WRITE_UNKNOWN(0x1700),
3941

4042
// 2xx: problem validating the request
4143
SYNTAX_ERROR(0x2000),

driver-core/src/main/java/com/datastax/driver/core/Responses.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
import com.datastax.driver.core.exceptions.AlreadyExistsException;
2525
import com.datastax.driver.core.exceptions.AuthenticationException;
2626
import com.datastax.driver.core.exceptions.BootstrappingException;
27+
import com.datastax.driver.core.exceptions.CASWriteUnknownException;
28+
import com.datastax.driver.core.exceptions.CDCWriteException;
2729
import com.datastax.driver.core.exceptions.DriverException;
2830
import com.datastax.driver.core.exceptions.DriverInternalError;
2931
import com.datastax.driver.core.exceptions.FunctionExecutionException;
@@ -119,6 +121,12 @@ public Error decode(ByteBuf body, ProtocolVersion version, CodecRegistry codecRe
119121
clt, received, blockFor, failures, failuresMap, dataPresent != 0);
120122
}
121123
break;
124+
case CAS_WRITE_UNKNOWN:
125+
clt = CBUtil.readConsistencyLevel(body);
126+
received = body.readInt();
127+
blockFor = body.readInt();
128+
infos = new CASWriteUnknownException(clt, received, blockFor);
129+
break;
122130
case UNPREPARED:
123131
infos = MD5Digest.wrap(CBUtil.readBytes(body));
124132
break;
@@ -173,6 +181,10 @@ DriverException asException(EndPoint endPoint) {
173181
return ((ReadFailureException) infos).copy(endPoint);
174182
case FUNCTION_FAILURE:
175183
return new FunctionExecutionException(endPoint, message);
184+
case CDC_WRITE_FAILURE:
185+
return new CDCWriteException(endPoint, message);
186+
case CAS_WRITE_UNKNOWN:
187+
return ((CASWriteUnknownException) infos).copy(endPoint);
176188
case SYNTAX_ERROR:
177189
return new SyntaxError(endPoint, message);
178190
case UNAUTHORIZED:
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
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.driver.core.exceptions;
17+
18+
import com.datastax.driver.core.ConsistencyLevel;
19+
import com.datastax.driver.core.EndPoint;
20+
21+
public class CASWriteUnknownException extends QueryConsistencyException {
22+
23+
private static final long serialVersionUID = 0;
24+
25+
/**
26+
* This constructor should only be used internally by the driver when decoding error responses.
27+
*/
28+
public CASWriteUnknownException(ConsistencyLevel consistency, int received, int required) {
29+
this(null, consistency, received, required);
30+
}
31+
32+
public CASWriteUnknownException(
33+
EndPoint endPoint, ConsistencyLevel consistency, int received, int required) {
34+
super(
35+
endPoint,
36+
String.format(
37+
"CAS operation result is unknown - proposal was not accepted by a quorum. (%d / %d)",
38+
received, required),
39+
consistency,
40+
received,
41+
required);
42+
}
43+
44+
private CASWriteUnknownException(
45+
EndPoint endPoint,
46+
String msg,
47+
Throwable cause,
48+
ConsistencyLevel consistency,
49+
int received,
50+
int required) {
51+
super(endPoint, msg, cause, consistency, received, required);
52+
}
53+
54+
@Override
55+
public CASWriteUnknownException copy() {
56+
return new CASWriteUnknownException(
57+
getEndPoint(),
58+
getMessage(),
59+
this,
60+
getConsistencyLevel(),
61+
getReceivedAcknowledgements(),
62+
getRequiredAcknowledgements());
63+
}
64+
65+
/**
66+
* Create a copy of this exception with a nicer stack trace, and including the coordinator address
67+
* that caused this exception to be raised.
68+
*
69+
* <p>This method is mainly intended for internal use by the driver and exists mainly because:
70+
*
71+
* <ol>
72+
* <li>the original exception was decoded from a response frame and at that time, the
73+
* coordinator address was not available; and
74+
* <li>the newly-created exception will refer to the current thread in its stack trace, which
75+
* generally yields a more user-friendly stack trace that the original one.
76+
* </ol>
77+
*
78+
* @param endPoint The full address of the host that caused this exception to be thrown.
79+
* @return a copy/clone of this exception, but with the given host address instead of the original
80+
* one.
81+
*/
82+
public CASWriteUnknownException copy(EndPoint endPoint) {
83+
return new CASWriteUnknownException(
84+
endPoint,
85+
getMessage(),
86+
this,
87+
getConsistencyLevel(),
88+
getReceivedAcknowledgements(),
89+
getRequiredAcknowledgements());
90+
}
91+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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.driver.core.exceptions;
17+
18+
import com.datastax.driver.core.EndPoint;
19+
import java.net.InetAddress;
20+
import java.net.InetSocketAddress;
21+
22+
/** An error occurred when trying to write a CDC mutation to the commitlog * */
23+
public class CDCWriteException extends QueryExecutionException implements CoordinatorException {
24+
25+
private static final long serialVersionUID = 0;
26+
27+
private final EndPoint endPoint;
28+
29+
public CDCWriteException(EndPoint endPoint, String message) {
30+
super(message);
31+
this.endPoint = endPoint;
32+
}
33+
34+
/** Private constructor used solely when copying exceptions. */
35+
private CDCWriteException(EndPoint endPoint, String message, CDCWriteException cause) {
36+
super(message, cause);
37+
this.endPoint = endPoint;
38+
}
39+
40+
@Override
41+
public EndPoint getEndPoint() {
42+
return endPoint;
43+
}
44+
45+
@Override
46+
@Deprecated
47+
public InetSocketAddress getAddress() {
48+
return (endPoint == null) ? null : endPoint.resolve();
49+
}
50+
51+
@Override
52+
@Deprecated
53+
public InetAddress getHost() {
54+
return (endPoint == null) ? null : endPoint.resolve().getAddress();
55+
}
56+
57+
@Override
58+
public CDCWriteException copy() {
59+
return new CDCWriteException(endPoint, getMessage(), this);
60+
}
61+
}

0 commit comments

Comments
 (0)