antoniopresto / react-native-local-mongodb

react-native local mongodb storage.
MIT License
304 stars 66 forks source link

Row too big to fit into CursorWindow #52

Closed nnoelwess-soft closed 5 years ago

nnoelwess-soft commented 5 years ago

When i try to update or insert documents (pdf file in string base64 format) in loop an exception is raised when I insert about twenty documents (but it's variable (15 - 20 docs))

Code js :

//call with axios webservice => Reponse.data var buffer64 = new Buffer(response.data, "binary").toString("base64"); console.log(buffer64.length); => // size of buffer64.length = 185476

updateDocPromise(query, newDoc) { //return this.insertDocPromise(newDoc); return new Promise((resolve, reject) => { dbMongo.update(query, newDoc, { upsert: true }, function( err, numReplaced ) { console.log("FUNCTION : updateDocPromise : " + newDoc.id);

    if (err != null) {
      console.log("FUNCTION : updateDocPromise : ERR ");
      console.log(ERR);
    }

    err ? reject(err) : resolve(numReplaced);
  });
});

}

Exception raised in Android studio logcat :

2019-02-28 16:17:07.092 7059-9470/ W/CursorWindow: Window is full: requested allocation 2127495 bytes, free space 2096688 bytes, window size 2097152 bytes 2019-02-28 16:17:07.092 7059-9470/ E/SQLiteQuery: exception: Row too big to fit into CursorWindow requiredPos=0, totalRows=1; query: SELECT key, value FROM catalystLocalStorage WHERE key IN (?) 2019-02-28 16:17:07.094 7059-9470/ W/unknown:ReactNative: Row too big to fit into CursorWindow requiredPos=0, totalRows=1 android.database.sqlite.SQLiteBlobTooBigException: Row too big to fit into CursorWindow requiredPos=0, totalRows=1 at android.database.sqlite.SQLiteConnection.nativeExecuteForCursorWindow(Native Method) at android.database.sqlite.SQLiteConnection.executeForCursorWindow(SQLiteConnection.java:904) at android.database.sqlite.SQLiteSession.executeForCursorWindow(SQLiteSession.java:851) at android.database.sqlite.SQLiteQuery.fillWindow(SQLiteQuery.java:62) at android.database.sqlite.SQLiteCursor.fillWindow(SQLiteCursor.java:149) at android.database.sqlite.SQLiteCursor.getCount(SQLiteCursor.java:137) at com.facebook.react.modules.storage.AsyncStorageModule$1.doInBackgroundGuarded(AsyncStorageModule.java:97) at com.facebook.react.modules.storage.AsyncStorageModule$1.doInBackgroundGuarded(AsyncStorageModule.java:81) at com.facebook.react.bridge.GuardedAsyncTask.doInBackground(GuardedAsyncTask.java:32) at com.facebook.react.bridge.GuardedAsyncTask.doInBackground(GuardedAsyncTask.java:20) at android.os.AsyncTask$2.call(AsyncTask.java:345) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:257) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) at java.lang.Thread.run(Thread.java:784)

Exception raised in Visual Studio code by react native :

[18:02:47] [Unhandled promise rejection: Error: Row too big to fit into CursorWindow requiredPos=0, totalRows=1]

  • node_modules/react-native/Libraries/Storage/AsyncStorage.js:339:22 in convertError
  • node_modules/react-native/Libraries/Storage/AsyncStorage.js:332:71 in
  • ... 7 more stack frames from framework internals

Unitarily my files are not very big 180 Ko, if I reduce the file size < 10ko I do not have any problem anymore in collection of 20 items . But I do not understand where the problem comes from, and if I can solve it

Android version API 28 Android 9 "react-native-local-mongodb": "^2.2.5",

Thanks for your help.

antoniopresto commented 5 years ago

Looks like a limitation with AsyncStorage. I’m planning to change the default storage, but PRs are welcome :)

for now, you can try this https://github.com/antoniopresto/react-native-local-mongodb/issues/42#issuecomment-432898339

nnoelwess-soft commented 5 years ago

Thank you for your quick feedback! In fact, each row i'm trying to insert are less than 200KB. It seem that the limitations is reach with 20 inserts approximatively, which concords with the 2MB CursorWindow limitation, but i thought that it was a limitation per row... What do you think, am I misusing anything?

antoniopresto commented 5 years ago

What do you think, am I misusing anything? I honestly do not have an answer. Feel free to reopen if you believe it is a bug in this lib.

silvafacundo commented 5 years ago

I've tried using redux-persist-filesystem-storage but I'm still getting this error Is this the correct setup?

import FilesystemStorage from 'redux-persist-filesystem-storage'
import Datastore from 'react-native-local-mongodb';
let mdb = new Datastore({filename:'name',storage:FilesystemStorage,autoload:true});
emannick commented 5 years ago

how to change AsyncStorage to something else to avoid CursorWindow issue.