Documentation ¶
Overview ¶
Package sqlannotation provides functions for annotating DML statements with keyspace-id comments and parsing them. These annotations are used during filtered-replication to route the DML statement to the correct shard. TOOD(erez): Move the code for the "_stream" annotations from vttablet to here.
Index ¶
- Constants
- func AddFilteredReplicationUnfriendly(sql string) string
- func AddFilteredReplicationUnfriendlyIfDML(sql string) string
- func AddIfDML(sql string, keyspaceIDs [][]byte) string
- func AddKeyspaceID(sql string, keyspaceID []byte) string
- func AddKeyspaceIDIfDML(sql string, keyspaceID []byte) string
- func ExtractKeySpaceID(sql string) (keyspaceID []byte, err error)
- type ExtractKeySpaceIDError
Constants ¶
const ( ExtractKeySpaceIDParseError = iota ExtractKeySpaceIDReplicationUnfriendlyError = iota )
Possible values for ExtractKeySpaceIDError.Kind
Variables ¶
This section is empty.
Functions ¶
func AddFilteredReplicationUnfriendly ¶
AddFilteredReplicationUnfriendly annotates the given 'sql' query as filtered-replication-unfriendly.
func AddFilteredReplicationUnfriendlyIfDML ¶
AddFilteredReplicationUnfriendlyIfDML annotates the given 'sql' query as filtered-replication-unfriendly if its a DML statement (filtered-replication should halt if it encounters such an annotation). Does nothing if the statement is not a DML statement.
func AddIfDML ¶
AddIfDML annotates 'sql' based on the keyspaceIDs found in 'keyspaceIDs':
If 'sql' is not a DML statement no annotation is added. If 'sql' is a DML statement and contains exactly one element it is used to annotate 'sql'; otherwise 'sql' is annotated as replication-unfriendly.
func AddKeyspaceID ¶
AddKeyspaceID returns a copy of 'sql' annotated with the given keyspace id.
func AddKeyspaceIDIfDML ¶
AddKeyspaceIDIfDML returns a copy of 'sql' annotated with the given keyspace id if 'sql' is a DML statement; otherwise, it returns a copy of 'sql'.
func ExtractKeySpaceID ¶
ExtractKeySpaceID parses the annotation of the given statement and tries to extract the keyspace id. If a keyspace-id comment exists 'keyspaceID' is set to the parsed keyspace id and err is set to nil; otherwise, if a filtered-replication-unfriendly comment exists or some other parsing error occured, keyspaceID is set to nil and err is set to a non-nil error value.
Types ¶
type ExtractKeySpaceIDError ¶
ExtractKeySpaceIDError is the error type returned from ExtractKeySpaceID Kind is a numeric code for the error (see constants below) and Message is an error message string.
func (ExtractKeySpaceIDError) Error ¶
func (err ExtractKeySpaceIDError) Error() string