MCPcopy Create free account
hub / github.com/datastax/cql-proxy / maybeStorePreparedMetadata

Method maybeStorePreparedMetadata

proxy/proxy.go:952–979  ·  view source on GitHub ↗

maybeStorePreparedMetadata stores the idempotence of a "PREPARE" request's query. This information is used by future "EXECUTE" requests when they need to be retried.

(raw *frame.RawFrame, isSelect bool, msg message.Message)

Source from the content-addressed store, hash-verified

950// maybeStorePreparedMetadata stores the idempotence of a "PREPARE" request's query.
951// This information is used by future "EXECUTE" requests when they need to be retried.
952func (c *client) maybeStorePreparedMetadata(raw *frame.RawFrame, isSelect bool, msg message.Message) {
953 logger := c.proxy.logger
954
955 if prepareMsg, ok := msg.(*message.Prepare); ok && raw.Header.OpCode == primitive.OpCodeResult { // Prepared result
956 frm, err := c.codec.ConvertFromRawFrame(raw)
957 if err != nil {
958 logger.Error("error attempting to decode prepared result message")
959 } else if preparedResultMsg, ok := frm.Body.Message.(*message.PreparedResult); !ok { // TODO: Use prepared type data to disambiguate idempotency
960 logger.Error("expected prepared result message, but got something else")
961 } else {
962 logger.Debug("prepared request",
963 zap.Stringer("request", prepareMsg),
964 zap.Stringer("response", preparedResultMsg))
965 idempotent, err := parser.IsQueryIdempotent(prepareMsg.Query)
966 if err != nil {
967 logger.Error("error parsing query for idempotence", zap.Error(err))
968 } else if result, ok := frm.Body.Message.(*message.PreparedResult); ok {
969 c.proxy.preparedMetadata.Store(preparedIdKey(result.PreparedQueryId), preparedMetadata{
970 idempotent: idempotent,
971 isSelect: isSelect,
972 })
973 } else {
974 logger.Error("expected prepared result, but got some other type of message",
975 zap.Stringer("type", reflect.TypeOf(frm.Body.Message)))
976 }
977 }
978 }
979}
980
981func getOrCreateDefaultPreparedCache(cache proxycore.PreparedCache) (proxycore.PreparedCache, error) {
982 if cache == nil {

Callers 1

OnResultMethod · 0.80

Calls 4

IsQueryIdempotentFunction · 0.92
preparedIdKeyFunction · 0.85
StoreMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected