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

io.objectbox.exception.DbFullException: Could not put #1199

Open
georgegatt opened this issue Dec 11, 2024 · 6 comments
Open

io.objectbox.exception.DbFullException: Could not put #1199

georgegatt opened this issue Dec 11, 2024 · 6 comments
Assignees
Labels
documentation Improvements or additions to documentation more info required Further information is requested
Milestone

Comments

@georgegatt
Copy link

Build info

  • Android Gradle plugin: 8.1.4
  • ObjectBox version: 3.3.1
  • OS: Android 14
  • Device: Samsung Galaxy S23 (Disk free: approximately 136 GB)
  • app's build.gradle properties: compileSdk 34 , buildToolsVersion '34.0.0' , targetSdk 34

Stacktrace from Crashlytics:

Caused by io.objectbox.exception.DbFullException: Could not put
      at io.objectbox.BoxStore.nativeCreateWithFlatOptions(BoxStore.java)
      at io.objectbox.BoxStore.<init>(BoxStore.java:269)
      at io.objectbox.BoxStoreBuilder.build(BoxStoreBuilder.java:516)
      at com.ObjectBox.computeProperMaxSizeInKByte(ObjectBox.java:84)
      at com.ObjectBox.init(ObjectBox.java:59)
      at com.itt.App.onCreate(App.java:23)
      at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1316)
      at android.app.ActivityThread.handleBindApplication(ActivityThread.java:7848)
      at android.app.ActivityThread.-$$Nest$mhandleBindApplication()
      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2486)
      at android.os.Handler.dispatchMessage(Handler.java:106)
      at android.os.Looper.loopOnce(Looper.java:230)
      at android.os.Looper.loop(Looper.java:319)
      at android.app.ActivityThread.main(ActivityThread.java:9063)
      at java.lang.reflect.Method.invoke(Method.java)
      at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:588)
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1103)      

As you can see, the crash happens during application launch inside the method:
computeProperMaxSizeInKByte(Context context)

while trying to execute the following code (this is the first line of code in the above method):
BoxStore boxStore = MyObjectBox.builder().androidContext(context.getApplicationContext()).build();

I was aware of the issue: #633 that causes the crash during a transaction,
but in my case there is no transaction, just an attempt to build the BoxStore instance.

@georgegatt georgegatt added the bug Something isn't working label Dec 11, 2024
@greenrobot greenrobot removed the bug Something isn't working label Dec 12, 2024
@greenrobot
Copy link
Member

First, "com.ObjectBox" is not our package and it's weird, ours is io.objectbox. So, is that "your" package?

For the Exception, https://objectbox.io/docfiles/java/current/io/objectbox/exception/DbFullException.html explains it with a solution.

but in my case there is no transaction, just an attempt to build the BoxStore instance.

Opening the store does internal transactions, which is perfectly normal.

All in all, not a bug.

@georgegatt
Copy link
Author

Yes, "com.ObjectBox" is our package not yours. As I mentioned above, the crash happens during application launch inside the method: computeProperMaxSizeInKByte(Context context)

while trying to execute the following code (this is the first line of code in the above method):
BoxStore boxStore = MyObjectBox.builder().androidContext(context.getApplicationContext()).build();

So, you mean that the Exception can be avoided by creating the boxStore as follows:
BoxStore boxStore = MyObjectBox.builder().androidContext(context.getApplicationContext()).maxSizeInKByte().build();

Am I correct ?

@greenrobot
Copy link
Member

Yes, you reached the default limit of 1 GB. This value a precaution in case your database keeps growing indefinitely.

@greenrobot-team
Copy link
Member

greenrobot-team commented Dec 16, 2024

Thanks for reporting! I clarified the class documentation to avoid the confusion about transactions and the default max size. Until released, here is a copy:

Thrown when applying a database operation would exceed the (default) maxSizeInKByte configured for the Store.

This can occur for operations like when an Object is put, at the point when the (internal) transaction is committed. Or when the Store is opened with a max size too small for the existing database.

Note: I labeled this issue with "more info required" so it will auto-close in a few days if there are no follow-up comments.

@greenrobot-team greenrobot-team added more info required Further information is requested documentation Improvements or additions to documentation labels Dec 16, 2024
@greenrobot-team greenrobot-team added this to the 4.0.4 milestone Dec 16, 2024
@greenrobot-team greenrobot-team self-assigned this Dec 16, 2024
@georgegatt
Copy link
Author

@greenrobot-team Just a minor clarification. You said:

Or when the Store is opened with a max size smaller than the existing database

The crash in our application appeared during the execution of the following code:
BoxStore boxStore = MyObjectBox.builder().androidContext(context.getApplicationContext()).build();

which as far as I understand, attempts to open the store without changing the max size property of the existing database.
Do you mean that the internal transactions during store opening, may require more space than the remaining free space of the database before it exceeds its max size set during the last session of the app ?

I forgot to mention, that in our app we use an algorithm that after store opening increases the max size when the remaining free space is less than 100 MB.

@github-actions github-actions bot removed the more info required Further information is requested label Dec 17, 2024
@greenrobot-team
Copy link
Member

greenrobot-team commented Dec 17, 2024

When maxSizeInKByte is not specified on MyObjectBox.builder() it uses the default size documented in the API docs, the database does not remember the max size set when last opening the Store.

It is possible that in your case the database was opened with a max size larger than the default before, then it is now tried to open with the smaller default max size and fails.

I also prepared a test to verify this will throw the Could not put error message and updated the wording about opening in my last comment:

Or when the Store is opened with a max size too small for the existing database.

At last, as I don't know the internals I'm not sure if there are any transactions when just opening the Store (which the Could not put message hints at). Also if they require more free space depending on how much existing data is in the database. I guess this and the max size calculation is a good thing to cover with unit tests in your code.

Note: I labeled this issue with "more info required" so it will auto-close in a few days if there are no follow-up comments.

@greenrobot-team greenrobot-team added the more info required Further information is requested label Dec 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation more info required Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants