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

Updates aren't retained after app restart #13

Closed
mingard opened this issue Dec 19, 2016 · 27 comments
Closed

Updates aren't retained after app restart #13

mingard opened this issue Dec 19, 2016 · 27 comments

Comments

@mingard
Copy link

mingard commented Dec 19, 2016

When using JSONBlockStore on the server, with clear=false, activate=true

Steps to reproduce:

  • Launch app
  • Insert document
  • Update document
  • Observe that document is updated (1)
  • Relaunch app
  • Get document (looks fine)
  • Update document
  • Observe that document is updated (2)
  • Relaunch app
  • Get document
  • Observe that document has reverted to the last version before the first App relaunch
@anywhichway anywhichway self-assigned this Dec 20, 2016
@mingard
Copy link
Author

mingard commented Dec 20, 2016

@anywhichway I can look at providing an example app build if that helps

@anywhichway
Copy link
Owner

Researching...

@anywhichway
Copy link
Owner

@mingard an example would certainly speed things-up. Would you like us to add a directory in master called issues/13? You could then create a repo and throw a pull request at us.

@mingard
Copy link
Author

mingard commented Dec 20, 2016

@anywhichway perfect - I'll start work on it now

@anywhichway
Copy link
Owner

@mingard we created a sample app in reasondb/test/issues/13/index.js and are unable to duplicate your issue. Please review the app to confirm it is able to accurately re-produce your steps. We will leave this issue open for a few days to give you an opportunity to respond.

@mingard
Copy link
Author

mingard commented Dec 26, 2016

@anywhichway thanks - I'll try and replicate it in-branch

@mingard
Copy link
Author

mingard commented Dec 26, 2016

@anywhichway I can't see the branch

@anywhichway
Copy link
Owner

@anywhichway anywhichway assigned mingard and unassigned anywhichway Dec 29, 2016
@mingard
Copy link
Author

mingard commented Dec 30, 2016

@anywhichway still working on this. Had some time off for Christmas

@anywhichway
Copy link
Owner

anywhichway commented Dec 30, 2016 via email

@mingard
Copy link
Author

mingard commented Jan 3, 2017

@anywhichway thanks, you too!

What version of Node/NPM are you running? I'm assuming higher than 4.7 as currently I strict mode errors where "use strict" hasn't been defined, like src/index.js

@mingard
Copy link
Author

mingard commented Jan 3, 2017

Once I upgrade to 6.x I get the following error:

const asynchronize = async (value) => {
	                           ^
SyntaxError: Unexpected token (

@anywhichway
Copy link
Owner

anywhichway commented Jan 3, 2017 via email

@mingard
Copy link
Author

mingard commented Jan 3, 2017

@anywhichway Okay, I've done the test a slightly different way. I need to be able to commit to a branch. You okay to create one, perhaps /issues/13?

@anywhichway
Copy link
Owner

@mingard I have created the branch issues/13

@mingard
Copy link
Author

mingard commented Jan 3, 2017

@anywhichway I am unable to commit to that branch

@anywhichway
Copy link
Owner

Can you clone it and submit a pull request?

@mingard
Copy link
Author

mingard commented Jan 3, 2017

@anywhichway see #14. I forked and opened a PR

@mingard
Copy link
Author

mingard commented Jan 9, 2017

@anywhichway any luck reproducing?

@anywhichway
Copy link
Owner

We are digging into why the select for Jack in script three returns "undefined". However, it does look like there is an error in the test, you explicitly change firstName to James below but then say you expect Jack to be returned.

 this.get(thirdInsert).then((docs) => {
    console.log(`We expect a result, as the Second script changed the name to "Jack", but we get ${docs[0]}`)
    console.log(`We revert back to "James" and try again`)
    thirdInsert.firstname = "James"
    this.get(thirdInsert).then((docs) => {
      console.log(`On the sixth GET, the returned document is ${docs[0].firstname} ${docs[0].lastname}. It should be Jack Smith`)
    })
  })

@mingard
Copy link
Author

mingard commented Jan 10, 2017

@anywhichway That's right, it should actually read James.

It seems that changes made during the same session as the document was created are stored, but those made in a subsequent process are stored in memory, but not persisted. Even a fetch during a second process returns the correct result suggesting that it has to be memory resident.

@anywhichway
Copy link
Owner

@mingard you are correct, We reached the same conclusion as you about the time of your post. We think the process may be ending prior to the data being written to disk. The manual termination we were using with the example of sequential runs that worked may be causing the write as a side effect. BTW, we duplicated the issue using ReasonDB.LocalStore which is a heck of a lot easier to debug than block storage.

@mingard
Copy link
Author

mingard commented Jan 11, 2017

@anywhichway That makes sense. I was using LocalStore originally but switched because it wasn't resolving referenced sub-documents after relaunch. I should probably raise a ticket for that too

@anywhichway
Copy link
Owner

anywhichway commented Jan 11, 2017

@mingard we have isolated the issue. ReasonDB caches constructors as it becomes aware of them. If it can't find a constructor it defaults to restoring data to plain Objects. In round two of and three of your test no inserts are occurring prior to selecting and no constructor has been cached. Your updates were actually getting written to disk but under the Object index not the Person index. We think this will be an easy fix, we just need to cache any constructors referenced by select, insert, update and delete prior to executing them. Currently the caching has been occurring lower in the call stack in case people are not using insert, select, etc.

@anywhichway
Copy link
Owner

anywhichway commented Jan 11, 2017

@mingard We think we have a fix. It is going to require some regression and we know we will have to make changes in a couple of spots; however, this seems to fix the situation for your example.

Modify the constructor for Index to be this:

constructor(cls,keyProperty="@key",db,StorageType=(db ? db.storageType : MemStore),clear=(db ? db.clear : false)) {
			const me = this;
			cls.index = me;
			me.saveAsync = db.saveIndexAsync;
			me.keys = {};
			me.store = new StorageType(cls.name,keyProperty,db,clear);
			me.store.scope[cls.name] = cls; // <--- this is the change
			me.name = cls.name;
			me.pending = {};
		}

Let us know if you confirm the fix. We may also be able to fix the issue with you having to manually create folders with the final patch.

@mingard
Copy link
Author

mingard commented Jan 11, 2017

@anywhichway that did it! Fix confirmed.

Am I right in thinking that if I'd inserted a document into Person on each process launch, it would've worked?

@anywhichway
Copy link
Owner

Yes, it should have ... Although we have uncovered an issue with our regression tests, too many use just Object rather than custom classes. We will push a new version for now and then add more tests.

Thanks for finding the bug! ... and confirming the fix.

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

No branches or pull requests

2 participants