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 dbStats for SQLite #3270

Merged
merged 28 commits into from
Aug 31, 2023

Conversation

chilagrow
Copy link
Member

@chilagrow chilagrow commented Aug 29, 2023

Description

Closes #3259.

It does not cover collStats, that will be in another PR.
In this issue we are not adding new integration tests, we want SQLite supported sooner, you'll notice codecov warning for untested errors. We will test them when we use universal handler in a few weeks time.

Readiness checklist

  • I added/updated unit tests (and they pass).
  • I added/updated integration/compatibility tests (and they pass).
  • I added/updated comments and checked rendering.
  • I made spot refactorings.
  • I updated user documentation.
  • I ran task all, and it passed.
  • I ensured that PR title is good enough for the changelog.
  • (for maintainers only) I set Reviewers (@FerretDB/core), Milestone (Next), Labels, Project and project's Sprint fields.
  • I marked all done items in this checklist.

@chilagrow chilagrow self-assigned this Aug 29, 2023
@chilagrow chilagrow added the code/feature Some user-visible feature is not implemented yet label Aug 29, 2023
@chilagrow chilagrow added this to the Next milestone Aug 29, 2023
@AlekSi AlekSi mentioned this pull request Aug 29, 2023
9 tasks
@mergify
Copy link
Contributor

mergify bot commented Aug 30, 2023

@chilagrow this pull request has merge conflicts.

@mergify mergify bot added the conflict PRs that have merge conflicts label Aug 30, 2023
@mergify mergify bot removed the conflict PRs that have merge conflicts label Aug 30, 2023
@codecov
Copy link

codecov bot commented Aug 30, 2023

Codecov Report

Merging #3270 (407190c) into main (37c183e) will decrease coverage by 0.01%.
The diff coverage is 72.47%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #3270      +/-   ##
==========================================
- Coverage   75.21%   75.21%   -0.01%     
==========================================
  Files         400      400              
  Lines       22901    23008     +107     
==========================================
+ Hits        17226    17306      +80     
- Misses       4683     4699      +16     
- Partials      992     1003      +11     
Files Changed Coverage
internal/handlers/pg/msg_dbstats.go ø
internal/handlers/sqlite/msg_dbstats.go 68.42%
internal/backends/sqlite/database.go 76.92%
Flag Coverage Δ
hana ?
integration 71.75% <72.47%> (+0.07%) ⬆️
mongodb 5.14% <0.00%> (-0.03%) ⬇️
pg 62.94% <0.00%> (-0.33%) ⬇️
shard-1 56.08% <72.47%> (+0.17%) ⬆️
shard-2 54.73% <69.72%> (+0.12%) ⬆️
shard-3 55.89% <37.61%> (-0.06%) ⬇️
sqlite 54.87% <72.47%> (+0.18%) ⬆️
unit 25.09% <36.69%> (+0.15%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

@chilagrow
Copy link
Member Author

chilagrow commented Aug 31, 2023

Response of implementation

test> db.runCommand({dbStats: 1})                                                                                                                                                                   [26/510]
{                                                                                                                                                                                                           
  db: 'test',                                                                                                                                                                                               
  collections: Long("0"),                                                                                                                                                                                   
  views: 0,                                                                                                                                                                                                 
  objects: Long("0"),                                                                                                                                                                                       
  dataSize: Long("0"),                                                                                                                                                                                      
  storageSize: Long("0"),                                                                                                                                                                                   
  indexes: Long("0"),                                                                                                                                                                                       
  indexSize: Long("0"),                                                                                                                                                                                     
  totalSize: Long("0"),                                                                                                                                                                                     
  scaleFactor: 1,                                                                                                                                                                                           
  ok: 1                                                                                                                                                                                                     
}                                                                                                                                                                                                           
test> db.coll.insertMany([{_id: 1}, {_id: 2}])                                                                                                                                                              
{ acknowledged: true, insertedIds: { '0': 1, '1': 2 } }                                                                                                                                                     
test> db.runCommand({dbStats: 1})                                                                                                                                                                           
{                                                                                                                                                                                                           
  db: 'test',                                                                                                                                                                                               
  collections: Long("1"),                                                                                                                                                                                   
  views: 0,                                                                                                                                                                                                 
  objects: Long("2"),                                                                                                                                                                                       
  avgObjSize: Long("2048"),                                                                                                                                                                                 
  dataSize: Long("4096"),                                                                                                                                                                                   
  storageSize: Long("4096"),                                                                                                                                                                                
  indexes: Long("0"),                                                                                                                                                                                       
  indexSize: Long("0"),                                                                                                                                                                                  
  totalSize: Long("32768"),                        
  scaleFactor: 1,                                  
  ok: 1                                            
}                                                  

@chilagrow
Copy link
Member Author

chilagrow commented Aug 31, 2023

Example of dbstat and sqlite_schema table contents, with empty collection new-collection and 2 documents collection coll.

sqlite> select name, pgsize, ncell from dbstat;
sqlite_schema|4096|8
_ferretdb_collections|4096|2
sqlite_autoindex__ferretdb_collections_1|4096|2
sqlite_autoindex__ferretdb_collections_2|4096|2
new-collection_82bca3b8|4096|0
new-collection_82bca3b8_id|4096|0
sqlite_stat1|4096|2
coll_f244e9a7|4096|2
coll_f244e9a7_id|4096|2

@chilagrow chilagrow marked this pull request as ready for review August 31, 2023 03:21
@chilagrow chilagrow requested a review from a team as a code owner August 31, 2023 03:21
@chilagrow chilagrow requested review from AlekSi, rumyantseva, a team and noisersup August 31, 2023 03:21
@chilagrow chilagrow enabled auto-merge (squash) August 31, 2023 03:21
rumyantseva
rumyantseva previously approved these changes Aug 31, 2023
Copy link
Contributor

@rumyantseva rumyantseva left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code looks reasonable to me

@chilagrow chilagrow merged commit 2be310a into FerretDB:main Aug 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
code/feature Some user-visible feature is not implemented yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Implement dbStats and collStats for SQLite
3 participants