|
@@ -58,6 +58,18 @@ ApiError translate(Code code, const std::string& message, const std::string& not
|
|
|
case Code::PermissionDenied:
|
|
case Code::PermissionDenied:
|
|
|
return ApiError(ErrCode::Forbidden, "forbidden", message);
|
|
return ApiError(ErrCode::Forbidden, "forbidden", message);
|
|
|
case Code::InvalidArgument:
|
|
case Code::InvalidArgument:
|
|
|
|
|
+ // database 2.13.1 refuses a write whose STORED document would grow
|
|
|
|
|
+ // past what a read could ever send back, checking the MERGED result
|
|
|
|
|
+ // of a patch rather than the request body - which is the case that
|
|
|
|
|
+ // matters, because the body was never the thing that crossed the
|
|
|
|
|
+ // line. We measured the hole it closes: a 60 MiB insert followed by
|
|
|
|
|
+ // patches reached ~100 MB, after which the row could not be read at
|
|
|
|
|
+ // all. Its own slug, because the remedy is "store less in this
|
|
|
|
|
+ // document", not "fix a malformed field" - which is what a generic
|
|
|
|
|
+ // `validation` answer would send a caller looking for.
|
|
|
|
|
+ if (reason == "document_too_large")
|
|
|
|
|
+ return ApiError(ErrCode::Unprocessable, "document_too_large", message, details);
|
|
|
|
|
+ return ApiError(ErrCode::Unprocessable, "validation", message);
|
|
|
case Code::OutOfRange:
|
|
case Code::OutOfRange:
|
|
|
return ApiError(ErrCode::Unprocessable, "validation", message);
|
|
return ApiError(ErrCode::Unprocessable, "validation", message);
|
|
|
case Code::ResourceExhausted:
|
|
case Code::ResourceExhausted:
|
|
@@ -105,8 +117,34 @@ ApiError translate(Code code, const std::string& message, const std::string& not
|
|
|
// briefly unavailable, retry as-is" - so it gets its own 409 rather
|
|
// briefly unavailable, retry as-is" - so it gets its own 409 rather
|
|
|
// than being folded into 503 as it was when it arrived as Unknown.
|
|
// than being folded into 503 as it was when it arrived as Unknown.
|
|
|
return ApiError(ErrCode::Conflict, "version_conflict", message, details);
|
|
return ApiError(ErrCode::Conflict, "version_conflict", message, details);
|
|
|
- case Code::Unavailable:
|
|
|
|
|
case Code::DeadlineExceeded:
|
|
case Code::DeadlineExceeded:
|
|
|
|
|
+ // A WRITE that timed out may or may not have been applied, and
|
|
|
|
|
+ // database 2.13.1 says so with reason `outcome_unknown`. Our old
|
|
|
|
|
+ // answer here was 503, whose entire meaning is "retry as-is" - and
|
|
|
|
|
+ // that is dangerous advice for a write that may already have
|
|
|
|
|
+ // landed. We measured the shape it describes: a patch reported
|
|
|
|
|
+ // DeadlineExceeded after three client retries while the row had
|
|
|
|
|
+ // grown by exactly the patched amount every time.
|
|
|
|
|
+ //
|
|
|
|
|
+ // 504 rather than 503 because it says the upstream ran out of time
|
|
|
|
|
+ // WITHOUT implying the retry is safe, and it is already what we
|
|
|
|
|
+ // answer for an embedding or fetch timeout. The message carries the
|
|
|
|
|
+ // instruction a caller actually needs, which is to RE-READ before
|
|
|
|
|
+ // deciding - not to retry and hope.
|
|
|
|
|
+ //
|
|
|
|
|
+ // A READ that times out is unambiguous and stays 503: nothing
|
|
|
|
|
+ // happened, so retrying as-is is exactly right.
|
|
|
|
|
+ if (reason == "outcome_unknown")
|
|
|
|
|
+ return ApiError(ErrCode::GatewayTimeout, "outcome_unknown",
|
|
|
|
|
+ message.empty()
|
|
|
|
|
+ ? "the write timed out and may or may not have been applied; "
|
|
|
|
|
+ "re-read the document before retrying, and do not blindly "
|
|
|
|
|
+ "retry a write that is not idempotent"
|
|
|
|
|
+ : message + " - the write may or may not have been applied; "
|
|
|
|
|
+ "re-read before retrying",
|
|
|
|
|
+ details);
|
|
|
|
|
+ return ApiError(ErrCode::Unavailable, "db_unavailable", message);
|
|
|
|
|
+ case Code::Unavailable:
|
|
|
return ApiError(ErrCode::Unavailable, "db_unavailable", message);
|
|
return ApiError(ErrCode::Unavailable, "db_unavailable", message);
|
|
|
// Unknown no longer covers the in-band refusals - since client 2.12.0
|
|
// Unknown no longer covers the in-band refusals - since client 2.12.0
|
|
|
// each one carries its own code. What is left here is a genuinely
|
|
// each one carries its own code. What is left here is a genuinely
|