Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add basic getMore command #2309

Merged
merged 20 commits into from
Mar 30, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Handle zero batch size
  • Loading branch information
AlekSi committed Mar 30, 2023
commit 29a70fa82dc04f311b482cbd6059918049e7e8e8
11 changes: 7 additions & 4 deletions internal/handlers/pg/msg_find.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,12 @@ func (h *Handler) MsgFind(ctx context.Context, msg *wire.OpMsg) (*wire.OpMsg, er

var resDocs []*types.Document
err = dbPool.InTransaction(ctx, func(tx pgx.Tx) error {
var iter types.DocumentsIterator
if iter, err = pgdb.QueryDocuments(ctx, tx, qp); err != nil {
if params.BatchSize == 0 {
return nil
}

iter, err := pgdb.QueryDocuments(ctx, tx, qp)
if err != nil {
return lazyerrors.Error(err)
}

Expand All @@ -103,8 +107,7 @@ func (h *Handler) MsgFind(ctx context.Context, msg *wire.OpMsg) (*wire.OpMsg, er

iter = common.SkipIterator(iter, params.Skip)

iter, err = common.ProjectionIterator(iter, params.Projection)
if err != nil {
if iter, err = common.ProjectionIterator(iter, params.Projection); err != nil {
return lazyerrors.Error(err)
}

Expand Down
57 changes: 33 additions & 24 deletions internal/handlers/tigris/msg_find.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,39 +63,48 @@ func (h *Handler) MsgFind(ctx context.Context, msg *wire.OpMsg) (*wire.OpMsg, er
qp.Filter = params.Filter
}

iter, err := dbPool.QueryDocuments(ctx, qp)
if err != nil {
return nil, lazyerrors.Error(err)
}
var resDocs []*types.Document

defer iter.Close()
err = func() error {
if params.BatchSize == 0 {
return nil
}

iter, err := dbPool.QueryDocuments(ctx, qp)
if err != nil {
return lazyerrors.Error(err)
}

iter = common.FilterIterator(iter, params.Filter)
defer iter.Close()

iter, err = common.SortIterator(iter, params.Sort)
if err != nil {
var pathErr *types.DocumentPathError
if errors.As(err, &pathErr) && pathErr.Code() == types.ErrDocumentPathEmptyKey {
return nil, commonerrors.NewCommandErrorMsgWithArgument(
commonerrors.ErrPathContainsEmptyElement,
"Empty field names in path are not allowed",
document.Command(),
)
iter = common.FilterIterator(iter, params.Filter)

iter, err = common.SortIterator(iter, params.Sort)
if err != nil {
var pathErr *types.DocumentPathError
if errors.As(err, &pathErr) && pathErr.Code() == types.ErrDocumentPathEmptyKey {
return commonerrors.NewCommandErrorMsgWithArgument(
commonerrors.ErrPathContainsEmptyElement,
"Empty field names in path are not allowed",
document.Command(),
)
}

return lazyerrors.Error(err)
}

return nil, lazyerrors.Error(err)
}
iter = common.LimitIterator(iter, params.Limit)

iter = common.LimitIterator(iter, params.Limit)
iter = common.SkipIterator(iter, params.Skip)

iter = common.SkipIterator(iter, params.Skip)
if iter, err = common.ProjectionIterator(iter, params.Projection); err != nil {
return lazyerrors.Error(err)
}

iter, err = common.ProjectionIterator(iter, params.Projection)
if err != nil {
return nil, lazyerrors.Error(err)
}
resDocs, err = iterator.ConsumeValues(iterator.Interface[struct{}, *types.Document](iter))
return err
}()

resDocs, err := iterator.ConsumeValues(iterator.Interface[struct{}, *types.Document](iter))
if err != nil {
return nil, lazyerrors.Error(err)
}
Expand Down