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

Implement MsgCount for Tigris #928

Merged
merged 22 commits into from
Jul 26, 2022
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
better use of error handling
  • Loading branch information
Elena Grahovac committed Jul 22, 2022
commit 8d6ca4f0b45965168dcc378a020f673023e774f1
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ require (
golang.org/x/exp v0.0.0-20220713135740-79cabaa25d75
golang.org/x/net v0.0.0-20220708220712-1185a9018129
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8
google.golang.org/grpc v1.48.0 // indirect
)

require (
Expand Down Expand Up @@ -59,6 +58,7 @@ require (
golang.org/x/text v0.3.7 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20220526192754-51939a95c655 // indirect
google.golang.org/grpc v1.48.0 // indirect
google.golang.org/protobuf v1.28.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
Expand Down
4 changes: 1 addition & 3 deletions internal/handlers/tigris/fetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ package tigris
import (
"context"

api "github.com/tigrisdata/tigris-client-go/api/server/v1"
"github.com/tigrisdata/tigris-client-go/driver"
"go.uber.org/zap"

Expand All @@ -43,8 +42,7 @@ func (h *Handler) fetch(ctx context.Context, param fetchParam) ([]*types.Documen
case nil:
// do nothing
case *driver.Error:
//nolint:nosnakecase // Tigris named their const that way
if err.Code == api.Code_NOT_FOUND {
if isNotFound(err) {
h.L.Debug(
"Collection doesn't exist, handling a case to deal with a non-existing collection (return empty list)",
zap.String("db", param.db), zap.String("collection", param.collection),
Expand Down
4 changes: 1 addition & 3 deletions internal/handlers/tigris/msg_drop.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ package tigris
import (
"context"

api "github.com/tigrisdata/tigris-client-go/api/server/v1"
"github.com/tigrisdata/tigris-client-go/driver"

"github.com/FerretDB/FerretDB/internal/handlers/common"
Expand Down Expand Up @@ -51,8 +50,7 @@ func (h *Handler) MsgDrop(ctx context.Context, msg *wire.OpMsg) (*wire.OpMsg, er
case nil:
// do nothing
case *driver.Error:
//nolint:nosnakecase // Tigris named their const that way
if err.Code == api.Code_NOT_FOUND {
if isNotFound(err) {
return nil, common.NewErrorMsg(common.ErrNamespaceNotFound, "ns not found")
}
return nil, lazyerrors.Error(err)
Expand Down
3 changes: 1 addition & 2 deletions internal/handlers/tigris/msg_dropdatabase.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ package tigris
import (
"context"

api "github.com/tigrisdata/tigris-client-go/api/server/v1"
"github.com/tigrisdata/tigris-client-go/driver"

"github.com/FerretDB/FerretDB/internal/handlers/common"
Expand Down Expand Up @@ -47,7 +46,7 @@ func (h *Handler) MsgDropDatabase(ctx context.Context, msg *wire.OpMsg) (*wire.O
case nil:
res.Set("dropped", db)
case *driver.Error:
if err.Code != api.Code_NOT_FOUND {
if !isNotFound(err) {
return nil, lazyerrors.Error(err)
}
// nothing otherwise
Expand Down
15 changes: 15 additions & 0 deletions internal/handlers/tigris/tigris.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"context"
"time"

api "github.com/tigrisdata/tigris-client-go/api/server/v1"
"github.com/tigrisdata/tigris-client-go/config"
"github.com/tigrisdata/tigris-client-go/driver"
"go.uber.org/zap"
Expand Down Expand Up @@ -69,6 +70,20 @@ func (h *Handler) Close() {
h.driver.Close()
}

// isNotFound returns true if the error is a "not found" error.
// This function is implemented to keep nolint in a single place.
func isNotFound(err *driver.Error) bool {
if err == nil {
return false
}

//nolint:nosnakecase // Tigris named their const that way
if err.Code == api.Code_NOT_FOUND {
return true
}
return false
}

// check interfaces
var (
_ handlers.Interface = (*Handler)(nil)
Expand Down