Class FailedMutation
- All Implemented Interfaces:
FailedElement
FailureHandler<FailedMutation>.
Carries the Mutation the serializer produced rather than the original record: the sink
writer is stateless and retains only mutations, so by the time the service rejects one the
original record object no longer exists. When serialization itself failed, getMutation()
and getTable() are null.
What the payload bytes are, and why
getPayloadBytes() is the Java-serialized Mutation, recovered with an
ObjectInputStream against the same client library. It is not a protobuf, and that is not
a choice: the Spanner client library exposes no public route from a Mutation to its wire
form — Mutation.toProtoAndReturnRandomMutation, Value.toProto(),
Key.toProto() and KeySet.appendToProto are all package-private (checked against
google-cloud-spanner 6.119.0). Nor can the debug rendering stand in: Mutation.toString()
truncates every string value at 36 characters, so it would hand a dead-letter consumer a payload
that looks complete and is not. Java serialization is the one non-lossy encoding the public API
offers, and Mutation, Value, Key and KeySet each declare a
serialVersionUID, so it is an affordance the library maintains rather than an accident.
A handler that wants the mutation itself should take FailureHandler<FailedMutation>
and read getMutation(); the bytes exist for the cross-connector DeadLetterQueue
view, which sees only FailedElement.
Instances are created by the sink and are not serializable.
-
Method Summary
Modifier and TypeMethodDescriptionReturns the destination asprojects/P/instances/I/databases/D/tables/T, or without the table segment when the record could not be serialized.getCause()Returns the underlying failure, ornullwhen none is available.Returns the connector that produced the failure, as a lower-case identifier ("bigquery","bigtable","cloudtasks","pubsub","spanner") — stable, so dead-letter consumers can key on it.Returns the database the mutation was routed to.Returns the failure description.com.google.cloud.spanner.MutationReturns the mutation the serializer produced, ornullwhen the record could not be serialized in the first place.com.google.protobuf.ByteStringReturns the Java-serialized mutation — see the class documentation for why it is not a protobuf — ornullwhen serialization itself failed.getTable()Returns the table the mutation applies to, ornullwhen the record could not be serialized.static FailedMutationof(DatabaseDestination database, com.google.cloud.spanner.Mutation mutation, String errorMessage, Throwable cause) Creates a failed mutation.toString()
-
Method Details
-
of
public static FailedMutation of(DatabaseDestination database, @Nullable com.google.cloud.spanner.Mutation mutation, String errorMessage, @Nullable Throwable cause) Creates a failed mutation. Intended for the sink implementation (and tests of custom handlers).- Parameters:
database- the database the mutation was routed tomutation- the mutation, ornullwhen serialization itself failederrorMessage- the failure descriptioncause- the underlying failure, ornull- Returns:
- the failed mutation
-
getDatabase
Returns the database the mutation was routed to. -
getMutation
@Nullable public com.google.cloud.spanner.Mutation getMutation()Returns the mutation the serializer produced, ornullwhen the record could not be serialized in the first place. -
getTable
Returns the table the mutation applies to, ornullwhen the record could not be serialized. -
getConnector
Description copied from interface:FailedElementReturns the connector that produced the failure, as a lower-case identifier ("bigquery","bigtable","cloudtasks","pubsub","spanner") — stable, so dead-letter consumers can key on it.- Specified by:
getConnectorin interfaceFailedElement
-
describeDestination
Returns the destination asprojects/P/instances/I/databases/D/tables/T, or without the table segment when the record could not be serialized.- Specified by:
describeDestinationin interfaceFailedElement
-
getPayloadBytes
@Nullable public com.google.protobuf.ByteString getPayloadBytes()Returns the Java-serialized mutation — see the class documentation for why it is not a protobuf — ornullwhen serialization itself failed.- Specified by:
getPayloadBytesin interfaceFailedElement
-
getErrorMessage
Description copied from interface:FailedElementReturns the failure description. It is always present, even whenFailedElement.getCause()isnull, and it is the detail thatFailureHandler.failJob()raises andFailureHandler.logAndDrop()logs.- Specified by:
getErrorMessagein interfaceFailedElement
-
getCause
Description copied from interface:FailedElementReturns the underlying failure, ornullwhen none is available.- Specified by:
getCausein interfaceFailedElement
-
toString
-