This page describes Spanner error codes and recommended actions to
handle these errors. Google APIs, including Spanner, use the
canonical error codes defined by google.rpc.Code
.
When a Spanner request is successful, the API returns an HTTP
200 OK
status code along with the requested data in the body of the response.
When a request fails, the Spanner API returns an HTTP
4xx
or 5xx
status code that generically identifies the failure as well as a
response that provides more specific information about the error(s) that caused
the failure.
The response object contains a single field error
whose value contains the
following elements:
Element | Description |
---|---|
code |
An HTTP status code that generically identifies the request failure. |
message |
Specific information about the request failure. |
status |
The canonical error code (google.rpc.Code ) for Google APIs. Codes that may be returned by the Spanner API are listed in Error Codes. |
If a request made with a content type of application/x-protobuf
results in an
error, it will return a serialized google.rpc.Status
message as the
payload.
Error codes
The recommended way to classify errors is to inspect the value of the
canonical error code (google.rpc.Code
). In JSON errors, this code appears
in the status
field. In application/x-protobuf
errors, it's in the code
field.
Error code | Description | Recommended action |
---|---|---|
ABORTED |
The operation was aborted, typically due to concurrency issue such as a sequencer check failure or transaction abort. Indicates that the request conflicted with another request. | For a non-transactional commit: Retry the request or structure your entities to reduce contention. For requests that are part of a transactional commit: Retry the entire transaction or structure your entities to reduce contention. |
ALREADY_EXISTS |
The entity that a client attempted to create already exists (for example, inserting a row with an existing primary key). | Don't retry without fixing the problem. |
CANCELLED |
The operation was cancelled, typically by the caller. | Retry the operation. |
DEADLINE_EXCEEDED |
The deadline expired before the operation could complete. | Investigate if the deadline is sufficient. Use a deadline corresponding to the actual time in which a response is useful. Note that for operations that change the state of the system, an error might be returned even if the operation has completed successfully. For tips, see Troubleshoot deadline exceeded errors. |
FAILED_PRECONDITION |
The operation was rejected because a precondition for the request was not met. The message field in the error response provides information about the precondition that failed. For example, reading or querying from a timestamp that has exceeded the maximum timestamp staleness. | Don't retry without fixing the problem. |
INTERNAL |
The server returned an error. Some invariants expected by the underlying system have been broken. | Don't retry unless you understand the specific circumstance and cause of the error. |
INVALID_ARGUMENT |
The client specified an invalid value. The message field in the error response provides information as to which value was invalid. | Don't retry without fixing the problem. |
NOT_FOUND |
Indicates that some requested entity, such as updating an entity or querying a table or column, doesn't exist. | Don't retry without fixing the problem. |
OUT_OF_RANGE |
The operation was attempted past the valid range. | Don't retry without fixing the problem. |
PERMISSION_DENIED |
The user was not authorized to make the request. | Don't retry without fixing the problem. |
RESOURCE_EXHAUSTED |
Some resource has been exhausted. For the administrator plane, it's possible that the project exceeded its quota or the entire file system is out of space. For the data plane, this can happen if your Spanner nodes are overloaded. |
For the administrator plane, verify that you didn't exceed your Spanner or project quota. If you've exceeded a quota, request a quota increase or wait for the quota to reset before trying again. Configure your retries to use exponential backoff. For the data plane, verify that your Spanner nodes haven't exceeded their capacity. Spanner retries these errors in the client library. If all retries fail, see Flow control mechanism errors. In general, if your application is experiencing RESOURCE_EXHAUSTED errors, treat the situation like an UNAVAILABLE error, and retry with exponential backoff. |
UNAUTHENTICATED |
The request doesn't have valid authentication credentials for the operation. | Don't retry without fixing the problem. |
UNAVAILABLE |
The server is unavailable. | Retry using exponential backoff. Note that it is not always safe to retry non-idempotent operations. |
UNIMPLEMENTED |
The operation is not implemented or is not supported/enabled in this service. | Don't retry without fixing the problem. |
UNKNOWN |
Server returned an unknown error. Errors raised by APIs that don't return enough error information may be converted to this error. | Check that your request is safe. Then, retry with exponential backoff. |
Flow control mechanism errors
Spanner might activate its flow control mechanism to protect itself from overload under the following conditions:
- There is high CPU usage on the Spanner node. If you suspect that your request is causing high CPU usage, then you can use the CPU utilization metrics to investigate the issue.
- There might be hotspots, which increase the processing time of the request. If you suspect that your request is causing hotspots, then you can use the Key Visualizer to investigate the issue.
The flow control mechanism is supported by the following client libraries:
The overall time for the request to complete won't increase due to the use of
the flow control mechanism. Without this mechanism, Spanner waits
before processing the request and eventually returns a DEADLINE_EXCEEDED
error.
When the flow control mechanism is active, Spanner pushes
requests back to the client to retry. If the retry consumes the entire
user-provided deadline, then the client receives a RESOURCE_EXHAUSTED
error.
This error is returned if Spanner estimates that the processing
time of the request is too long. The error propagates flow control and
Spanner retries the request to the client, instead of
accumulating retries internally. This allows Spanner to avoid
accumulating additional resource consumption.