-
Notifications
You must be signed in to change notification settings - Fork 409
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 collStats
for SQLite
#3295
Merged
AlekSi
merged 22 commits into
FerretDB:main
from
chilagrow:issue-3259-collstats-sqlite-impt
Sep 4, 2023
Merged
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
894798e
add backend interface for collection statistics
chilagrow 37ba896
initial impl of collStats for SQLite
chilagrow bb37eae
Merge branch 'main' into issue-3259-collstats-sqlite
chilagrow 8841ee5
add Database prefix for params and result of Stats method
chilagrow 11f71ee
merge
chilagrow 85cf7ee
merge
chilagrow c5227a4
collStats indexes fail for SQLite
chilagrow 2c7a11f
return error on non existing collection
chilagrow b959cee
totalSize for collStats is size of index and table
chilagrow 79e435d
fix error message
chilagrow beb6686
update test, cleanup
chilagrow f1e8cad
tidy up
chilagrow a08f4ae
update godoc
chilagrow 338fa48
Merge branch 'issue-3259-collstats-sqlite' into issue-3259-collstats-…
chilagrow 8678a76
lint
chilagrow e0485c8
merge conflict
chilagrow 4e1b47d
add test
chilagrow 03defb2
merge conflict
chilagrow 8141d40
use state provider in test
chilagrow 1ff5889
stats on DB returns error on not found DB
chilagrow f7f5dc5
update test
chilagrow d69ffef
Merge branch 'main' into issue-3259-collstats-sqlite-impt
AlekSi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
initial impl of collStats for SQLite
- Loading branch information
commit 37ba896a8844e810e5be868a37d4a77204627317
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
// Copyright 2021 FerretDB Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package sqlite | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/FerretDB/FerretDB/internal/backends" | ||
"github.com/FerretDB/FerretDB/internal/backends/sqlite/metadata" | ||
"github.com/FerretDB/FerretDB/internal/util/testutil" | ||
) | ||
|
||
func TestStats(t *testing.T) { | ||
t.Parallel() | ||
ctx := testutil.Ctx(t) | ||
|
||
r, err := metadata.NewRegistry("file:./?mode=memory", testutil.Logger(t)) | ||
require.NoError(t, err) | ||
t.Cleanup(r.Close) | ||
|
||
dbName := t.Name() | ||
db := newDatabase(r, dbName) | ||
|
||
t.Cleanup(func() { | ||
db.Close() | ||
}) | ||
|
||
t.Run("NonExistingDatabase", func(t *testing.T) { | ||
var res *backends.StatsResult | ||
res, err = db.Stats(ctx, new(backends.StatsParams)) | ||
require.NoError(t, err) | ||
require.Equal(t, new(backends.StatsResult), res) | ||
}) | ||
|
||
collectionOne := "collectionOne" | ||
err = db.CreateCollection(ctx, &backends.CreateCollectionParams{Name: collectionOne}) | ||
require.NoError(t, err) | ||
require.NotNil(t, db) | ||
|
||
collectionTwo := "collectionTwo" | ||
err = db.CreateCollection(ctx, &backends.CreateCollectionParams{Name: collectionTwo}) | ||
require.NoError(t, err) | ||
require.NotNil(t, db) | ||
|
||
t.Cleanup(func() { | ||
r.DatabaseDrop(ctx, dbName) | ||
}) | ||
|
||
var dbStatsRes *backends.StatsResult | ||
t.Run("EmptyCollection", func(t *testing.T) { | ||
dbStatsRes, err = db.Stats(ctx, new(backends.StatsParams)) | ||
require.NoError(t, err) | ||
require.NotZero(t, dbStatsRes.SizeTotal) | ||
require.NotZero(t, dbStatsRes.CountCollections) | ||
require.NotZero(t, dbStatsRes.SizeCollections) | ||
require.Zero(t, dbStatsRes.CountObjects) | ||
}) | ||
|
||
t.Run("CollectionOne", func(t *testing.T) { | ||
res, err := db.Stats(ctx, &backends.StatsParams{Collection: collectionOne}) | ||
require.NoError(t, err) | ||
require.NotZero(t, res.SizeTotal) | ||
require.Less(t, res.SizeTotal, dbStatsRes.SizeTotal) | ||
require.Equal(t, res.CountCollections, int64(1)) | ||
require.NotZero(t, res.SizeCollections) | ||
require.Less(t, res.SizeCollections, dbStatsRes.SizeCollections) | ||
require.Zero(t, res.CountObjects) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix
https://www.mongodb.com/docs/manual/reference/command/collStats/#mongodb-data-collStats.storageSize