Skip to content

Commit

Permalink
Merge branch 'main' into mysql/backend
Browse files Browse the repository at this point in the history
  • Loading branch information
adetunjii authored Jan 23, 2024
2 parents a63d45c + 2729421 commit 2ab50d5
Show file tree
Hide file tree
Showing 64 changed files with 312 additions and 273 deletions.
12 changes: 6 additions & 6 deletions internal/clientconn/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,9 +258,9 @@ func (c *conn) run(ctx context.Context) (err error) {
protoErr := handlererrors.ProtocolError(validationErr)

var res wire.OpMsg
must.NoError(res.SetSections(wire.OpMsgSection{
Documents: []*types.Document{protoErr.Document()},
}))
must.NoError(res.SetSections(wire.MakeOpMsgSection(
protoErr.Document(),
)))

b := must.NotFail(res.MarshalBinary())

Expand Down Expand Up @@ -479,9 +479,9 @@ func (c *conn) route(ctx context.Context, reqHeader *wire.MsgHeader, reqBody wir
protoErr := handlererrors.ProtocolError(err)

var res wire.OpMsg
must.NoError(res.SetSections(wire.OpMsgSection{
Documents: []*types.Document{protoErr.Document()},
}))
must.NoError(res.SetSections(wire.MakeOpMsgSection(
protoErr.Document(),
)))
resBody = &res

switch protoErr := protoErr.(type) {
Expand Down
22 changes: 12 additions & 10 deletions internal/handler/cmd_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ import (

// CmdQuery implements deprecated OP_QUERY message handling.
func (h *Handler) CmdQuery(ctx context.Context, query *wire.OpQuery) (*wire.OpReply, error) {
cmd := query.Query.Command()
cmd := query.Query().Command()
collection := query.FullCollectionName

// both are valid and are allowed to be run against any database as we don't support authorization yet
if (cmd == "ismaster" || cmd == "isMaster") && strings.HasSuffix(collection, ".$cmd") {
return common.IsMaster(ctx, query.Query, h.TCPHost, h.ReplSetName)
return common.IsMaster(ctx, query.Query(), h.TCPHost, h.ReplSetName)
}

// TODO https://github.com/FerretDB/FerretDB/issues/3008
Expand All @@ -42,15 +42,17 @@ func (h *Handler) CmdQuery(ctx context.Context, query *wire.OpQuery) (*wire.OpRe

if cmd == "saslStart" && strings.HasSuffix(collection, ".$cmd") {
var emptyPayload types.Binary
return &wire.OpReply{
reply := wire.OpReply{
NumberReturned: 1,
Documents: []*types.Document{must.NotFail(types.NewDocument(
"conversationId", int32(1),
"done", true,
"payload", emptyPayload,
"ok", float64(1),
))},
}, nil
}
reply.SetDocument(must.NotFail(types.NewDocument(
"conversationId", int32(1),
"done", true,
"payload", emptyPayload,
"ok", float64(1),
)))

return &reply, nil
}

return nil, handlererrors.NewCommandErrorMsgWithArgument(
Expand Down
11 changes: 6 additions & 5 deletions internal/handler/common/count.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,12 @@ type CountParams struct {

Fields any `ferretdb:"fields,ignored"` // legacy MongoDB shell adds it, but it is never actually used

Hint any `ferretdb:"hint,ignored"`
ReadConcern *types.Document `ferretdb:"readConcern,ignored"`
Comment string `ferretdb:"comment,ignored"`
LSID any `ferretdb:"lsid,ignored"`
ClusterTime any `ferretdb:"$clusterTime,ignored"`
Hint any `ferretdb:"hint,ignored"`
ReadConcern *types.Document `ferretdb:"readConcern,ignored"`
Comment string `ferretdb:"comment,ignored"`
LSID any `ferretdb:"lsid,ignored"`
ClusterTime any `ferretdb:"$clusterTime,ignored"`
ReadPreference *types.Document `ferretdb:"$readPreference,ignored"`
}

// GetCountParams returns the parameters for the count command.
Expand Down
7 changes: 4 additions & 3 deletions internal/handler/common/delete_params.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@ type DeleteParams struct {

Let *types.Document `ferretdb:"let,unimplemented"`

WriteConcern *types.Document `ferretdb:"writeConcern,ignored"`
LSID any `ferretdb:"lsid,ignored"`
ClusterTime any `ferretdb:"$clusterTime,ignored"`
WriteConcern *types.Document `ferretdb:"writeConcern,ignored"`
LSID any `ferretdb:"lsid,ignored"`
ClusterTime any `ferretdb:"$clusterTime,ignored"`
ReadPreference *types.Document `ferretdb:"$readPreference,ignored"`
}

// Delete represents single delete operation parameters.
Expand Down
7 changes: 4 additions & 3 deletions internal/handler/common/distinct.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,10 @@ type DistinctParams struct {

Collation *types.Document `ferretdb:"collation,unimplemented"`

ReadConcern *types.Document `ferretdb:"readConcern,ignored"`
LSID any `ferretdb:"lsid,ignored"`
ClusterTime any `ferretdb:"$clusterTime,ignored"`
ReadConcern *types.Document `ferretdb:"readConcern,ignored"`
LSID any `ferretdb:"lsid,ignored"`
ClusterTime any `ferretdb:"$clusterTime,ignored"`
ReadPreference *types.Document `ferretdb:"$readPreference,ignored"`
}

// GetDistinctParams returns `distinct` command parameters.
Expand Down
15 changes: 8 additions & 7 deletions internal/handler/common/find.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,14 @@ type FindParams struct {
Collation *types.Document `ferretdb:"collation,unimplemented"`
Let *types.Document `ferretdb:"let,unimplemented"`

AllowDiskUse bool `ferretdb:"allowDiskUse,ignored"`
ReadConcern *types.Document `ferretdb:"readConcern,ignored"`
Max *types.Document `ferretdb:"max,ignored"`
Min *types.Document `ferretdb:"min,ignored"`
Hint any `ferretdb:"hint,ignored"`
LSID any `ferretdb:"lsid,ignored"`
ClusterTime any `ferretdb:"$clusterTime,ignored"`
AllowDiskUse bool `ferretdb:"allowDiskUse,ignored"`
ReadConcern *types.Document `ferretdb:"readConcern,ignored"`
Max *types.Document `ferretdb:"max,ignored"`
Min *types.Document `ferretdb:"min,ignored"`
Hint any `ferretdb:"hint,ignored"`
LSID any `ferretdb:"lsid,ignored"`
ClusterTime any `ferretdb:"$clusterTime,ignored"`
ReadPreference *types.Document `ferretdb:"$readPreference,ignored"`

ReturnKey bool `ferretdb:"returnKey,unimplemented-non-default"`
OplogReplay bool `ferretdb:"oplogReplay,ignored"`
Expand Down
1 change: 1 addition & 0 deletions internal/handler/common/findandmodify.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ type FindAndModifyParams struct {
BypassDocumentValidation bool `ferretdb:"bypassDocumentValidation,ignored"`
LSID any `ferretdb:"lsid,ignored"`
ClusterTime any `ferretdb:"$clusterTime,ignored"`
ReadPreference *types.Document `ferretdb:"$readPreference,ignored"`
}

// GetFindAndModifyParams returns `findAndModifyParams` command parameters.
Expand Down
12 changes: 7 additions & 5 deletions internal/handler/common/ismaster.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,16 @@ func IsMaster(ctx context.Context, query *types.Document, tcpHost, name string)
return nil, lazyerrors.Error(err)
}

return &wire.OpReply{
reply := wire.OpReply{
NumberReturned: 1,
Documents: IsMasterDocuments(tcpHost, name),
}, nil
}
reply.SetDocument(IsMasterDocument(tcpHost, name))

return &reply, nil
}

// IsMasterDocuments returns isMaster's Documents field (identical for both OP_MSG and OP_QUERY).
func IsMasterDocuments(tcpHost, name string) []*types.Document {
func IsMasterDocument(tcpHost, name string) *types.Document {
doc := must.NotFail(types.NewDocument(
"ismaster", true, // only lowercase
// topologyVersion
Expand Down Expand Up @@ -66,5 +68,5 @@ func IsMasterDocuments(tcpHost, name string) []*types.Document {
doc.Set("hosts", must.NotFail(types.NewArray(tcpHost)))
}

return []*types.Document{doc}
return doc
}
1 change: 1 addition & 0 deletions internal/handler/common/update_params.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ type UpdateParams struct {
WriteConcern *types.Document `ferretdb:"writeConcern,ignored"`
LSID any `ferretdb:"lsid,ignored"`
ClusterTime any `ferretdb:"$clusterTime,ignored"`
ReadPreference *types.Document `ferretdb:"$readPreference,ignored"`
}

// Update represents a single update operation parameters.
Expand Down
8 changes: 4 additions & 4 deletions internal/handler/msg_aggregate.go
Original file line number Diff line number Diff line change
Expand Up @@ -382,16 +382,16 @@ func (h *Handler) MsgAggregate(ctx context.Context, msg *wire.OpMsg) (*wire.OpMs
}

var reply wire.OpMsg
must.NoError(reply.SetSections(wire.OpMsgSection{
Documents: []*types.Document{must.NotFail(types.NewDocument(
must.NoError(reply.SetSections(wire.MakeOpMsgSection(
must.NotFail(types.NewDocument(
"cursor", must.NotFail(types.NewDocument(
"firstBatch", firstBatch,
"id", cursorID,
"ns", dbName+"."+cName,
)),
"ok", float64(1),
))},
}))
)),
)))

return &reply, nil
}
Expand Down
8 changes: 4 additions & 4 deletions internal/handler/msg_buildinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ func (h *Handler) MsgBuildInfo(ctx context.Context, msg *wire.OpMsg) (*wire.OpMs
}

var reply wire.OpMsg
must.NoError(reply.SetSections(wire.OpMsgSection{
Documents: []*types.Document{must.NotFail(types.NewDocument(
must.NoError(reply.SetSections(wire.MakeOpMsgSection(
must.NotFail(types.NewDocument(
"version", version.Get().MongoDBVersion,
"gitVersion", version.Get().Commit,
"modules", must.NotFail(types.NewArray()),
Expand All @@ -52,8 +52,8 @@ func (h *Handler) MsgBuildInfo(ctx context.Context, msg *wire.OpMsg) (*wire.OpMs
)),

"ok", float64(1),
))},
}))
)),
)))

return &reply, nil
}
6 changes: 3 additions & 3 deletions internal/handler/msg_collstats.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,9 @@ func (h *Handler) MsgCollStats(ctx context.Context, msg *wire.OpMsg) (*wire.OpMs
)

var reply wire.OpMsg
must.NoError(reply.SetSections(wire.OpMsgSection{
Documents: []*types.Document{must.NotFail(types.NewDocument(pairs...))},
}))
must.NoError(reply.SetSections(wire.MakeOpMsgSection(
must.NotFail(types.NewDocument(pairs...)),
)))

return &reply, nil
}
8 changes: 4 additions & 4 deletions internal/handler/msg_compact.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,12 @@ func (h *Handler) MsgCompact(ctx context.Context, msg *wire.OpMsg) (*wire.OpMsg,
}

var reply wire.OpMsg
must.NoError(reply.SetSections(wire.OpMsgSection{
Documents: []*types.Document{must.NotFail(types.NewDocument(
must.NoError(reply.SetSections(wire.MakeOpMsgSection(
must.NotFail(types.NewDocument(
"bytesFreed", float64(bytesFreed),
"ok", float64(1),
))},
}))
)),
)))

return &reply, nil
}
8 changes: 4 additions & 4 deletions internal/handler/msg_connectionstatus.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,16 @@ func (h *Handler) MsgConnectionStatus(ctx context.Context, msg *wire.OpMsg) (*wi
}

var reply wire.OpMsg
must.NoError(reply.SetSections(wire.OpMsgSection{
Documents: []*types.Document{must.NotFail(types.NewDocument(
must.NoError(reply.SetSections(wire.MakeOpMsgSection(
must.NotFail(types.NewDocument(
"authInfo", must.NotFail(types.NewDocument(
"authenticatedUsers", users,
"authenticatedUserRoles", must.NotFail(types.NewArray()),
"authenticatedUserPrivileges", must.NotFail(types.NewArray()),
)),
"ok", float64(1),
))},
}))
)),
)))

return &reply, nil
}
8 changes: 4 additions & 4 deletions internal/handler/msg_count.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,12 @@ func (h *Handler) MsgCount(ctx context.Context, msg *wire.OpMsg) (*wire.OpMsg, e
n, _ := count.(int32)

var reply wire.OpMsg
must.NoError(reply.SetSections(wire.OpMsgSection{
Documents: []*types.Document{must.NotFail(types.NewDocument(
must.NoError(reply.SetSections(wire.MakeOpMsgSection(
must.NotFail(types.NewDocument(
"n", n,
"ok", float64(1),
))},
}))
)),
)))

return &reply, nil
}
8 changes: 4 additions & 4 deletions internal/handler/msg_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,11 @@ func (h *Handler) MsgCreate(ctx context.Context, msg *wire.OpMsg) (*wire.OpMsg,
switch {
case err == nil:
var reply wire.OpMsg
must.NoError(reply.SetSections(wire.OpMsgSection{
Documents: []*types.Document{must.NotFail(types.NewDocument(
must.NoError(reply.SetSections(wire.MakeOpMsgSection(
must.NotFail(types.NewDocument(
"ok", float64(1),
))},
}))
)),
)))

return &reply, nil

Expand Down
6 changes: 3 additions & 3 deletions internal/handler/msg_createindexes.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,9 @@ func (h *Handler) MsgCreateIndexes(ctx context.Context, msg *wire.OpMsg) (*wire.
resp.Set("ok", float64(1))

var reply wire.OpMsg
must.NoError(reply.SetSections(wire.OpMsgSection{
Documents: []*types.Document{resp},
}))
must.NoError(reply.SetSections(wire.MakeOpMsgSection(
resp,
)))

return &reply, nil
}
Expand Down
8 changes: 4 additions & 4 deletions internal/handler/msg_createuser.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,11 +210,11 @@ func (h *Handler) MsgCreateUser(ctx context.Context, msg *wire.OpMsg) (*wire.OpM
}

var reply wire.OpMsg
must.NoError(reply.SetSections(wire.OpMsgSection{
Documents: []*types.Document{must.NotFail(types.NewDocument(
must.NoError(reply.SetSections(wire.MakeOpMsgSection(
must.NotFail(types.NewDocument(
"ok", float64(1),
))},
}))
)),
)))

return &reply, nil
}
8 changes: 4 additions & 4 deletions internal/handler/msg_currentop.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ import (
// MsgCurrentOp implements `currentOp` command.
func (h *Handler) MsgCurrentOp(ctx context.Context, msg *wire.OpMsg) (*wire.OpMsg, error) {
var reply wire.OpMsg
must.NoError(reply.SetSections(wire.OpMsgSection{
Documents: []*types.Document{must.NotFail(types.NewDocument(
must.NoError(reply.SetSections(wire.MakeOpMsgSection(
must.NotFail(types.NewDocument(
"inprog", must.NotFail(types.NewArray()),
"ok", float64(1),
))},
}))
)),
)))

return &reply, nil
}
8 changes: 4 additions & 4 deletions internal/handler/msg_datasize.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,15 @@ func (h *Handler) MsgDataSize(ctx context.Context, msg *wire.OpMsg) (*wire.OpMsg
}

var reply wire.OpMsg
must.NoError(reply.SetSections(wire.OpMsgSection{
Documents: []*types.Document{must.NotFail(types.NewDocument(
must.NoError(reply.SetSections(wire.MakeOpMsgSection(
must.NotFail(types.NewDocument(
"estimate", false,
"size", stats.SizeTotal,
"numObjects", stats.CountDocuments,
"millis", int32(time.Since(started).Milliseconds()),
"ok", float64(1),
))},
}))
)),
)))

return &reply, nil
}
6 changes: 3 additions & 3 deletions internal/handler/msg_dbstats.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,9 @@ func (h *Handler) MsgDBStats(ctx context.Context, msg *wire.OpMsg) (*wire.OpMsg,
)

var reply wire.OpMsg
must.NoError(reply.SetSections(wire.OpMsgSection{
Documents: []*types.Document{must.NotFail(types.NewDocument(pairs...))},
}))
must.NoError(reply.SetSections(wire.MakeOpMsgSection(
must.NotFail(types.NewDocument(pairs...)),
)))

return &reply, nil
}
6 changes: 3 additions & 3 deletions internal/handler/msg_debugerror.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ func (h *Handler) MsgDebugError(ctx context.Context, msg *wire.OpMsg) (*wire.OpM
"ok", float64(1),
))

must.NoError(reply.SetSections(wire.OpMsgSection{
Documents: []*types.Document{replyDoc},
}))
must.NoError(reply.SetSections(wire.MakeOpMsgSection(
replyDoc,
)))

return &reply, nil

Expand Down
Loading

0 comments on commit 2ab50d5

Please sign in to comment.