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

Changing some documents requires application restart #6080

Closed
kerner1000 opened this issue May 3, 2016 · 6 comments
Closed

Changing some documents requires application restart #6080

kerner1000 opened this issue May 3, 2016 · 6 comments
Assignees
Labels

Comments

@kerner1000
Copy link

kerner1000 commented May 3, 2016

I have difficulties keeping my table and the database in sync. After modifying some documents, my GUI does not display the latest changes.

Also a
database.reload();
database.close();
database.open();

does not help.

Only after restarting the whole application, I can see the changes.
Is there anything going on behind the scenes when shutting down the JVM? How can I ensure I query for the latest version of my documents?

@luigidellaquila
Copy link
Member

Hi @kerner1000

Could you please share some additional info about your application? How are you using OrientDB? Embedded or remote?

A little hint (but it's definitely a guess), try a db.getLocalCache().clear()

Thanks

Luigi

@kerner1000
Copy link
Author

Hi Luigi
db.getLocalCache().clear() worked! Thanks so much! I already wasted days on this topic.
But I am wondering what is 'best practices' do deal with this caching? I doubt I am the only one running into unexpected behavior here.

About our setup:

We establish a db connection basically at application startup:

ODatabaseDocumentTx db = OPartitionedDatabasePool.acquire()

and shut it down only when the application shuts down.

db.close()

For all reading and writing we use the same instance of db and do everything single threaded (multi thread access was causing us some other headaches)

after each document alteration, we call document.save().

We do not use transactions.

We could not figure out a decent way to perform save() in a more intelligent way.

I would be great if you could share some 'best practices' on saving documents, caching and maybe multi thread access!

Many thanks for helping!

Best,
Alex

@luigidellaquila
Copy link
Member

Hi Alex

OrientDB multi-threading can be tricky, because ODatabaseDocumentTx is not thread safe. What we recommend is that every thread opens and uses its own db connection, this should be safe in general.

About the save operations, if you are working in remote I suggest you to do small transactions instead, this way you will have network communication only at commit() and not at every save(), with obvious performance improvement. Just pay attention to the transaction isolation when you mix java and SQL (http://orientdb.com/docs/2.1/Transactions.html)

Thanks

Luigi

@tglman
Copy link
Member

tglman commented May 4, 2016

Hi,

Can i add something on top of this, do an 'OPartitionedDatabasePool.acquire()' at the start of the application is not really the way orientdb was thought, the correct way to use it creating the pool at startup, and acquiring/releasing the ODatabaseDocument on group of operations/methods, with the standard pattern:

ODatabaseDocument db = null
try {
    db = pool.acquire();
    //do your operation here 
} finally {
   if(db != null)
     db.close();
}

or more concise java7 syntax.

try(ODatabaseDocument db = pool.acquire()){
   //Do your operation here
}

this follow the same pattern of many ORMs or of JDBC with the a connection pool.

@kerner1000
Copy link
Author

kerner1000 commented May 6, 2016

Hi all,

thanks for your explanations. Can I find somewhere documentation about database caching? (db.getLocalCache())
When should I generally clear the cache and when not? ;)
Many thanks!

@laa
Copy link
Member

laa commented May 24, 2016

Hi guys, please never call db.getLocalCache() directly. It may lead to serious data consistency problems. If you have to clear cache it means that you incorrectly use DB API.

@laa laa closed this as completed Aug 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

4 participants