ekaterinadimitrova2 commented on code in PR #3955:
URL: https://github.com/apache/cassandra/pull/3955#discussion_r2014136069
##########
src/java/org/apache/cassandra/exceptions/RequestFailureReason.java:
##########
@@ -53,26 +59,31 @@ public enum RequestFailureReason
this.code = code;
}
- private static final RequestFailureReason[] codeToReasonMap;
+ private static final Map<Integer, RequestFailureReason> codeToReasonMap =
new HashMap<>();
+ private static final Map<Class<? extends Throwable>, RequestFailureReason>
exceptionToReasonMap = new HashMap<>();
static
{
RequestFailureReason[] reasons = values();
- int max = -1;
- for (RequestFailureReason r : reasons)
- max = max(r.code, max);
-
- RequestFailureReason[] codeMap = new RequestFailureReason[max + 1];
-
for (RequestFailureReason reason : reasons)
{
- if (codeMap[reason.code] != null)
+ if (codeToReasonMap.put(reason.code, reason) != null)
throw new RuntimeException("Two RequestFailureReason-s that
map to the same code: " + reason.code);
- codeMap[reason.code] = reason;
}
- codeToReasonMap = codeMap;
+ exceptionToReasonMap.put(TombstoneOverwhelmingException.class,
READ_TOO_MANY_TOMBSTONES);
+ exceptionToReasonMap.put(WriteTimeoutException.class, TIMEOUT);
+ exceptionToReasonMap.put(IncompatibleSchemaException.class,
INCOMPATIBLE_SCHEMA);
+ exceptionToReasonMap.put(ReadSizeAbortException.class, READ_SIZE);
+ exceptionToReasonMap.put(IndexNotAvailableException.class,
INDEX_NOT_AVAILABLE);
+ exceptionToReasonMap.put(NotCMSException.class, NOT_CMS);
+ exceptionToReasonMap.put(InvalidRoutingException.class,
INVALID_ROUTING);
+ exceptionToReasonMap.put(CoordinatorBehindException.class,
COORDINATOR_BEHIND);
+ exceptionToReasonMap.put(IndexBuildInProgressException.class,
INDEX_BUILD_IN_PROGRESS);
+
+ if (exceptionToReasonMap.size() != reasons.length-3)
+ throw new RuntimeException("A new RequestFailureReasons was
probably added and you may need to update the exceptionToReasonMap");
Review Comment:
Actually, the size check was also to make people not forget to add
exceptions.
If we do just
```
if (reason.exception != null)
exceptionToReasonMap.put(reason.exception, reason);
```
we lose that... And then we can end up again with `UNKNOWN` from
`forException`
I can probably add a unit test to catch that, but we are just moving it to
CI and it can be still missed, plus you get the signal only when you get to CI.
Earlier feedback while coding sounds better to me.
Let me know what you prefer
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]