Description
Write operations on the MarkLogic database can run into an error due to optimistic locking. In our implementation we want to deal with this sort of error and are trying to implement a retry-mechanism. Our problem is, that the error due optimistic locking is hard to distinguish from all the other errors (connection issues, authorization issues, syntactical problems in the request, ...) because for all of them only a FailedRequestException is thrown. The only(?) way to get the underlying error is currently a string comparision on the exception's message, which is a brittle approach.
This is how we currently detect an error due to optimistic locking:
try {
manager.write(documentDescriptor, writeHandle);
} catch (FailedRequestException e) {
// catch errors due optimistic locking and re-attempt the update.
if (e.getMessage().contains("RESTAPI-CONTENTWRONGVERSION")) {
/* snipped: we retry by reading the document again, manipulate it and try to write it again. */
}
}
(manager is here an XMLDocumentManager)
Our feature request is: Is it feasible to create an OptimisticLockingException? The OptimisticLockingException could be a subclass of the already existing FailedRequestException, then no APIs have to be changed. We could simplify and harden our implementation to:
try {
manager.write(documentDescriptor, writeHandle);
} catch (OptimisticLockingException e) {
/* snipped: we retry by reading the document again, manipulate it and try to write it again. */
}
Thank you in advance!