objectbox-java icon indicating copy to clipboard operation
objectbox-java copied to clipboard

Get database size and available capacity

Open greenrobot opened this issue 5 years ago • 6 comments

Add ways to retrieve information about sizes, e.g.:

  • database size on disk
  • current size limit on disk
  • information about free space in the current file. This is not trivial and could be e.g. based on free pages and pages with capacity. Might be an approximation. Could be a percentage or an absolute number.
  • optional(?): approximate remaining capacity until we reach max size (and/or disk limit). Details tbd...

greenrobot avatar Feb 11 '20 11:02 greenrobot

Great.

With these APIs, I can better improve my logic for dynamically expanding DB file size.

Although according to your design, this is not very realistic, if you can solve the DbFullException generated by calling io.objectbox.Box # remove or io.objectbox.Box # removeAll methods when the DB file capacity reaches its limit, it will be more perfect. So I don’t need to use these "rescue" methods

https://gist.github.com/greenrobot/5078a4c86f4fadc5c25711b0a90ecf3a or https://gist.github.com/teffy/1a4c1bd3c4e3eb776efb837f830efed2

teffy avatar Feb 11 '20 12:02 teffy

FYI: 2.7.0 has BoxStore.sizeOnDisk()

greenrobot avatar Jul 30 '20 19:07 greenrobot

FYI: 2.7.0 has BoxStore.sizeOnDisk()

remove entries does not make sizeOnDisk be smaller, so the method who returns unused 'pages' is needed for me.

In my story, the when db is full I will try to delete some oldest entries ( those data are time series data). I cannot remove all db files, thus customers will kill me for sure.

srdgame avatar Jun 30 '23 01:06 srdgame

One possible way for now :

  1. Do not set the max db size when initialize box store
  2. Record the max db count when it reached the max size in first time.
  3. Delete entries when reach max count when it has been set, delete 10% of total count of box store

In this way, db size should be nearly shaped to max db size. I guess so....

srdgame avatar Jun 30 '23 03:06 srdgame

@srdgame Maybe the new experimental maxDataSizeInKByte​ property is helpful in this case.

greenrobot-team avatar Jul 03 '23 08:07 greenrobot-team

@srdgame Maybe the new experimental maxDataSizeInKByte​ property is helpful in this case.

Possibly, but I won't test it any more, which is a painful time.

srdgame avatar Aug 24 '23 10:08 srdgame