objectbox-java: Could not remove entities when DB is full

Issue Basics

  • ObjectBox version (are using the latest version?): 2.2.0
  • Reproducibility: Always

Reproducing the bug

Description

I set the maxSizeInKByte to 256MB, but calling remove method when DB is full would cause a DbFullException which prevents me to remove entities to make DB not been full. Removing all selected ids once or removing them one by one would both cause DbFullException.

Code

try
{
    Box.remove(entityIds);
}
catch (DbException e)
{
    Log.e(TAG, "Removing entities was failed e:" + e.toString());

    for (long entityId : entityIds)
    {
        try
        {
            Box.remove(entityId);
        }
        catch (DbException e1)
        {
            Log.e(TAG, "Removing entity one-by-one was failed e:" + e1.toString());
        }
    }
}

Logs & stackstraces

10-16 15:45:43.829 E/AndroidRuntime( 5232): Process: com.example.objectbox, PID: 5232
10-16 15:45:43.829 E/AndroidRuntime( 5232): org.greenrobot.eventbus.EventBusException: Invoking subscriber failed
10-16 15:45:43.829 E/AndroidRuntime( 5232): 	at org.greenrobot.eventbus.EventBus.handleSubscriberException(EventBus.java:527)
10-16 15:45:43.829 E/AndroidRuntime( 5232): 	at org.greenrobot.eventbus.EventBus.invokeSubscriber(EventBus.java:509)
10-16 15:45:43.829 E/AndroidRuntime( 5232): 	at org.greenrobot.eventbus.EventBus.invokeSubscriber(EventBus.java:501)
10-16 15:45:43.829 E/AndroidRuntime( 5232): 	at org.greenrobot.eventbus.AsyncPoster.run(AsyncPoster.java:46)
10-16 15:45:43.829 E/AndroidRuntime( 5232): 	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
10-16 15:45:43.829 E/AndroidRuntime( 5232): 	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
10-16 15:45:43.829 E/AndroidRuntime( 5232): 	at java.lang.Thread.run(Thread.java:818)
10-16 15:45:43.829 E/AndroidRuntime( 5232): Caused by: io.objectbox.exception.DbFullException: Could not put (error code -30792)
10-16 15:45:43.829 E/AndroidRuntime( 5232): 	at io.objectbox.Cursor.nativeDeleteEntity(Native Method)
10-16 15:45:43.829 E/AndroidRuntime( 5232): 	at io.objectbox.Cursor.deleteEntity(Cursor.java:203)
10-16 15:45:43.829 E/AndroidRuntime( 5232): 	at io.objectbox.Box.remove(Box.java:472)
10-16 15:45:43.829 E/AndroidRuntime( 5232): 	at com.example.objectbox.util.EntityUtils.removeEntities(EntityUtils.java:524)
10-16 15:45:43.829 E/AndroidRuntime( 5232): 	at com.example.objectbox.service.DatabaseService.onRemoveEntities(DatabaseService.java:70)
10-16 15:45:43.829 E/AndroidRuntime( 5232): 	at java.lang.reflect.Method.invoke(Native Method)
10-16 15:45:43.829 E/AndroidRuntime( 5232): 	at java.lang.reflect.Method.invoke(Method.java:372)
10-16 15:45:43.829 E/AndroidRuntime( 5232): 	at org.greenrobot.eventbus.EventBus.invokeSubscriber(EventBus.java:507)

Misc

Box.removeAll() would not cause DbFullException, but I want to remove part of the enities instead of all of them.

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 20 (9 by maintainers)

Most upvoted comments

To put it simply, our business logic is to collect events that are continuously generated by the Android system and the business logic on a Android device running 7x24 hours, but we cannot let the size of the database file keep increasing for android disk limit, so we first delete some unimportant data, and Properly expand the size of the database file.

Therefore, we actually rely on APIs that can delete data in batches, such as io.objectbox.Box # removeAll and io.objectbox.Box # remove (java.util.Collection <T>).

Could be solved by using Box.count() as a workaround now but would be better to have the feature which could tell KBytes of the Box as https://github.com/objectbox/objectbox-java/issues/585 describes