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

Support create for capped collections #3614

Merged
merged 35 commits into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
09c7c21
wip
rumyantseva Oct 19, 2023
acfc3eb
wip
rumyantseva Oct 19, 2023
36cafbf
wip
rumyantseva Oct 19, 2023
6b03ca0
wip
rumyantseva Oct 19, 2023
2b288d5
wip
rumyantseva Oct 19, 2023
8f57936
wip
rumyantseva Oct 19, 2023
a1ac944
Merge branch 'main' into issue-3458-create
Oct 19, 2023
53fe697
wip
rumyantseva Oct 19, 2023
0155136
wip
rumyantseva Oct 19, 2023
c825d42
Update internal/backends/sqlite/metadata/registry.go
Oct 20, 2023
8d24039
wip
rumyantseva Oct 20, 2023
b5ccc14
wip
rumyantseva Oct 20, 2023
ce23e40
wip
rumyantseva Oct 20, 2023
578bade
wip
rumyantseva Oct 20, 2023
7b49f0b
Update integration/commands_administration_compat_test.go
Oct 20, 2023
4dfab8c
Merge branch 'main' into issue-3458-create
Oct 20, 2023
b8eb619
wip
rumyantseva Oct 20, 2023
1a9299c
Merge branch 'issue-3458-create' of https://github.com/rumyantseva/Fe…
rumyantseva Oct 20, 2023
bf1d2ab
wip
rumyantseva Oct 20, 2023
799d049
wip
rumyantseva Oct 20, 2023
278972d
wip
rumyantseva Oct 20, 2023
e2eeae6
Merge branch 'main' into issue-3458-create
Oct 20, 2023
04b06b6
wip
rumyantseva Oct 20, 2023
132cf75
Better error
rumyantseva Oct 23, 2023
3eed980
Merge branch 'main' into issue-3458-create
AlekSi Oct 23, 2023
907c4af
wip
rumyantseva Oct 23, 2023
d269272
Merge branch 'issue-3458-create' of https://github.com/rumyantseva/Fe…
rumyantseva Oct 23, 2023
ec8755e
wip
rumyantseva Oct 23, 2023
48dc636
Update internal/backends/postgresql/metadata/metadata.go
Oct 23, 2023
f75012a
Update internal/backends/sqlite/metadata/settings.go
Oct 23, 2023
562d2cd
Update integration/commands_administration_compat_test.go
Oct 23, 2023
aef0773
wip
rumyantseva Oct 24, 2023
afc5470
refactor
chilagrow Oct 24, 2023
eeaa953
cleanup
chilagrow Oct 24, 2023
8d836d7
Merge branch 'main' into issue-3458-create
AlekSi Oct 24, 2023
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
Next Next commit
wip
  • Loading branch information
rumyantseva committed Oct 19, 2023
commit 09c7c2110f6d5790a03ee8d6cf475397a5a98b24
8 changes: 4 additions & 4 deletions internal/backends/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ type ListCollectionsResult struct {
// CollectionInfo represents information about a single collection.
type CollectionInfo struct {
Name string
CappedSize int64 // TODO https://github.com/FerretDB/FerretDB/issues/3458
CappedDocuments int64 // TODO https://github.com/FerretDB/FerretDB/issues/3458
CappedSize int64
CappedDocuments int64
}

// Capped returns true if collection is capped.
Expand Down Expand Up @@ -119,8 +119,8 @@ func (dbc *databaseContract) ListCollections(ctx context.Context, params *ListCo
// CreateCollectionParams represents the parameters of Database.CreateCollection method.
type CreateCollectionParams struct {
Name string
CappedSize int64 // TODO https://github.com/FerretDB/FerretDB/issues/3458
CappedDocuments int64 // TODO https://github.com/FerretDB/FerretDB/issues/3458
CappedSize int64
CappedDocuments int64
}

// Capped returns true if capped collection creation is requested.
Expand Down
41 changes: 28 additions & 13 deletions internal/handlers/sqlite/msg_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ func (h *Handler) MsgCreate(ctx context.Context, msg *wire.OpMsg) (*wire.OpMsg,
unimplementedFields := []string{
"timeseries",
"expireAfterSeconds",
"size", // TODO https://github.com/FerretDB/FerretDB/issues/3458
"max", // TODO https://github.com/FerretDB/FerretDB/issues/3458
"size",
"max",
"validator",
"validationLevel",
"validationAction",
Expand All @@ -50,14 +50,6 @@ func (h *Handler) MsgCreate(ctx context.Context, msg *wire.OpMsg) (*wire.OpMsg,
return nil, err
}

// TODO https://github.com/FerretDB/FerretDB/issues/3458
if err = common.UnimplementedNonDefault(document, "capped", func(v any) bool {
b, ok := v.(bool)
return ok && !b
}); err != nil {
return nil, err
}

ignoredFields := []string{
"autoIndexId",
"storageEngine",
Expand All @@ -79,6 +71,31 @@ func (h *Handler) MsgCreate(ctx context.Context, msg *wire.OpMsg) (*wire.OpMsg,
return nil, err
}

params := backends.CreateCollectionParams{
Name: collectionName,
}

capped, err := common.GetOptionalParam[bool](document, "capped", false)
if err != nil {
return nil, err
}

if capped {
AlekSi marked this conversation as resolved.
Show resolved Hide resolved
size, err := common.GetRequiredParam[int64](document, "size")
if err != nil {
return nil, err
chilagrow marked this conversation as resolved.
Show resolved Hide resolved
}

params.CappedSize = size

max, err := common.GetOptionalParam[int64](document, "max", 0)
if err != nil {
return nil, err
}

params.CappedDocuments = max
}

db, err := h.b.Database(dbName)
if err != nil {
if backends.ErrorCodeIs(err, backends.ErrorCodeDatabaseNameIsInvalid) {
Expand All @@ -89,9 +106,7 @@ func (h *Handler) MsgCreate(ctx context.Context, msg *wire.OpMsg) (*wire.OpMsg,
return nil, lazyerrors.Error(err)
}

err = db.CreateCollection(ctx, &backends.CreateCollectionParams{
Name: collectionName,
})
err = db.CreateCollection(ctx, &params)

switch {
case err == nil:
Expand Down
Loading