Stale data and outdated @version values are being returned after performing an Edge update operation in OrientDB version 3.2.34 and later. #10727
|
Hello, I am performing an update operation on an edge and then attempting to retrieve the updated value. However, after executing the SELECT query, the OrientDB API returns stale data for the edge. The returned record does not reflect the updated attribute value, and the @Version is also outdated. When I check the same record in OrientDB Studio, the updated values and the correct version are displayed. Below are the steps to reproduce. Step 1 : Schema setup Step 2 : Create database connection using OPartitionedDatabasePool- Step 3 : Create Edge from A to B: Step 4 : Update Edge A to B: Step 5 : Fetch Updated Edge: Why is the Java API returning stale document data after executing the query while OrientDB Studio shows the correct updated version? Note: I have also filed issue for same : #10726 Thanks |
Replies: 1 comment 1 reply
|
Technical Explanation: The L1 Cache Issue However, when you execute an SQL UPDATE via db.command(), the local cache in your current session is not always automatically synchronized with the changes made on the server side.
The Conflict: When you run db.command("UPDATE..."), it is processed as a server-side SQL command. The Result: When you subsequently run a SELECT, the API sees that a record with that specific ORID already exists in your local memory. Instead of fetching the fresh data from the disk/server, it returns the stale version from the cache, which still has the old @Version. Studio vs. API: OrientDB Studio shows the correct data because every query in Studio typically runs in a fresh, isolated session, avoiding the stale cache of your long-running Java session.
Java SQL Java |
Technical Explanation: The L1 Cache Issue
The behavior you are experiencing is a classic case of Session-level Caching (L1 Cache) in OrientDB. When you use ODatabaseDocument (via OPartitionedDatabasePool), the driver keeps local copies of objects in memory to optimize performance.
However, when you execute an SQL UPDATE via db.command(), the local cache in your current session is not always automatically synchronized with the changes made on the server side.
OrientDB utilizes a Local Transaction Cache. When a record is loaded or created, it is stored in the cache of that specific db instance.
The Conflict: When you run db.command("UPDATE..."), it is processed as a …