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.paperdb.PaperDbException: Couldn't rename file #77

Closed
madhanmallow opened this issue Jun 13, 2017 · 7 comments
Closed

io.paperdb.PaperDbException: Couldn't rename file #77

madhanmallow opened this issue Jun 13, 2017 · 7 comments

Comments

@madhanmallow
Copy link

What is the reason for this exception and how to handle this?

@pilgr
Copy link
Owner

pilgr commented Jun 13, 2017

Could you provide a more detailed stack trace?

@madhanmallow
Copy link
Author

W/System.err: io.paperdb.PaperDbException: Couldn't rename file /data/user/0/com.redtaxi.driver/files/io.paperdb/travelTime.pt to backup file /data/user/0/
W/System.err: at io.paperdb.DbStoragePlainFile.insert(DbStoragePlainFile.java:117)
W/System.err: at io.paperdb.Book.write(Book.java:36)
W/System.err: at com.redtaxi.driver.fragments.RTTripBillFragment.removePrefsValues(RTTripBillFragment.java:158)
W/System.err: at com.redtaxi.driver.fragments.RTTripBillFragment.onCreateView(RTTripBillFragment.java:67)
W/System.err: at android.support.v4.app.Fragment.performCreateView(Fragment.java:2087)
W/System.err: at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1113)
W/System.err: at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1295)
W/System.err: at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:801)
W/System.err: at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1682)
W/System.err: at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:541)
W/System.err: at android.os.Handler.handleCallback(Handler.java:739)
W/System.err: at android.os.Handler.dispatchMessage(Handler.java:95)
W/System.err: at android.os.Looper.loop(Looper.java:148)
W/System.err: at android.app.ActivityThread.main(ActivityThread.java:5417)
W/System.err: at java.lang.reflect.Method.invoke(Native Method)
W/System.err: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
W/System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

@pilgr
Copy link
Owner

pilgr commented Jun 13, 2017

Paper renames the original file to file "*.bak" on writing attempt to have a way to recover in case if writing is failed.
https://github.com/pilgr/Paper/blob/master/paperdb/src/main/java/io/paperdb/DbStoragePlainFile.java#L115
The issues may happen because the original data file is locked for some reasons. Do you use the same Paper instance for all read/write operations? Using different Paper instances may cause data inconsistency and crashes like this.

How often does issue happen? Can you provide a test case or a sample code to reproduce it?

@madhanmallow
Copy link
Author

I'm using Paper.book().read() and Paper.book().write() throughout the app. My app also have two services running in background which also uses the above methods. Will this cause the issue?

@pilgr
Copy link
Owner

pilgr commented Jul 27, 2017

Two services running in one process or in different processes? Paper doesn't support data consistency when accessed from different processes.

@madhanmallow
Copy link
Author

They are running in two separate processes. How to handle this? Please suggest me a solution.

@pilgr
Copy link
Owner

pilgr commented Jul 28, 2017

Keep all the code accessing Paper in one process, let's say the main process where Paper can be accessed from activities and services. This main process should expose Binder interface with all the necessary API to get data. So another process can use Binder interface to access data without knowing anything about Paper underhood.
(Service with Paper, Process1 )*(BINDER)<-(Another service, Process2)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants