objectbox / objectbox-dart

Flutter database for super-fast Dart object persistence
https://docs.objectbox.io/getting-started
Apache License 2.0
927 stars 115 forks source link

Put and PutMany function throws [ERROR] Storage error (code -30786) #485

Closed KorayLiman closed 1 year ago

KorayLiman commented 1 year ago

Hi,

I'm trying to put 1500-2000 objects (1-2mb) with put and putMany method(only using putMany but tried put also) but i'm getting this error always in IOS and sometimes in Android too.

[ERROR] Storage error (code -30786) flutter: ObjectBoxException: object put failed: 10199 Could not put (-30786)

More information:

outrelouxhe commented 1 year ago

I have same kind of issue. Is there a reason why you have closed this issue without any comments? Did you find a solution? Thank you

KorayLiman commented 1 year ago

Hi. Yes i have found the problem. The reason was I marked a property as @Unique(). This annotation has a parameter called ConflictStrategy and it is set to fail by default in case of any duplicate of that value. But in my case there were no duplicates means that all values were already unique. So there were no conflicts but interestingly when i removed @Unique(), database started to function properly.

greenrobot-team commented 1 year ago

Using @Unique creates an index on a property, which consumes additional memory than just putting an object. It's possible that by not creating the index the remaining memory was enough to insert the new data.

Note for us: the internal error is MDB_PAGE_FULL - Page has not enough space.

greenrobot-team commented 1 year ago

@KorayLiman Actually it would help us if you could share more details (maybe some code snippets of your entity and the code that puts them) that allow us to reproduce this. If possible, also what exact devices this fails on.

CuriousDev21 commented 1 year ago

I am also having a similar of using putmany of around 20 objects and getting the exception: Unhandled Exception: StorageException: object put failed: Could not put (-30786) (OBX_ERROR code 10199)

Can anyone provide any direction, I can't see to find any documentations or online resources to help with this matter.

entity code snippet:

@Entity()
class TripStoreModel {
  late int id;

  @Unique(onConflict: ConflictStrategy.replace)
  int tripId;

  bool? tripSynchronized;
  int? vehicleId;
  String? vehicleName;
....
}
greenrobot commented 1 year ago

@Overlord21 Thanks for reporting. Would it be possible that you provide additional information? The more info we have the more likely it is that we can support and potentially fix something. Are you seeing this issue on iOS, on Android, or on both? Is it always reproducible? Can you provide a minimal sample (project) to reproduce this? That would be really appreciated!

greenrobot commented 1 year ago

See also https://github.com/objectbox/objectbox-swift/issues/72

greenrobot-team commented 1 year ago

Was also reported for Java https://github.com/objectbox/objectbox-java/issues/1099

Internally tracked as objectbox/objectbox-dart#33.

greenrobot-team commented 1 year ago

From https://github.com/objectbox/objectbox-swift/issues/72: workarounds appear to be to

greenrobot commented 1 year ago

The issue was fixed for iPhones internally. The background for this was that iOS has a system parameter with a different value from all other platforms. E.g. the iOS Simulator did not have this behavior - at least on Intel.

We'll investigate if Android could be affected by the same issue on some brands/devices.

KorayLiman commented 1 year ago

@greenrobot We ran into this problem on some Android devices as well but as I remember it was not often as IOS devices.

greenrobot commented 1 year ago

@KorayLiman OK, can you say if it was limited to certain devices/models on Android? This could help verifying. Also, we'll likely update Android too, on a just in case basis at least...

KorayLiman commented 1 year ago

Yes it was occurring on some specific devices only, like (1 or 2 out of 10) , not on all Android devices but didn't really investigate deeply about which specific devices/models that problem occurs on.

greenrobot-team commented 1 year ago

We have released version 1.7.2 which should fix this issue. Update to this version using flutter pub upgrade. Let us know if this resolves the issue for you.