orientdb icon indicating copy to clipboard operation
orientdb copied to clipboard

Backwards incompatible API changes to setIdentity, setVersion

Open stebbi opened this issue 11 years ago • 12 comments

Hi,

I'm using OrientDB as a new data store for an existing application. I frequently (1) query for one or more ODocument objects, (2) convert the objects to an alternate representation expected by a legacy API, (3) pass the converted objects to the legacy API and get new objects with changes, and (4) synthesize new ODocument objects to write back to the store.

When I synthesize the ODocument objects, I use setIdentity and setVersion to ensure that OrientDB correctly updates the objects I was working with, so they're stored using the old RIDs and new version numbers. Otherwise I'd wind up with copies, where each update would create a new RID.

All of this was fine with OrientDB 1.7.* but no longer works with 2.0-rc1. The ORecordAbstract.setIdentity and ORecordAbstract.setVersion methods are now protected and my codebase basically breaks.

I'd appreciate if the methods could be made public again, or if not, then there should be a workaround for the case I have described, where OrientDB-backed objects have to be processed by libraries with APIs that take something other than e.g. ODocument & friends.

stebbi avatar Dec 21 '14 16:12 stebbi

Fully agree, that it's inconvinient.

As wrokaround you can load document for your rid, change doc and then save it again. But, agree, it's not good for performance.

PhantomYdn avatar Dec 21 '14 18:12 PhantomYdn

@stebbi that two api were made protected on purpose, because should not be part of a normal application flow, anyway for your case i see the reason, let me discuss with the rest of the team on that.

by the way the correct flow is the one described by @PhantomYdn.

we also have some internal api that can be used for that purpose, but is internal staff that can change also in case of minor version, so is not really suggested use it.

I'll let you know ASAP of workaround or api back to public.

tglman avatar Dec 22 '14 10:12 tglman

Hi both,

Thanks for the prompt responses, appreciate. Alright, if it is an intentional attempt at steering people to safer usage, then definitely don't let me get in the way. Ilia's approach is fine for me, for now.

If the queries become a problem there is always the option of sticking the ODocs into memcached or an in-process object hash, using rid:version for the key. Since I'm limiting my OrientDB lookups to a single process, I can put a hash in an STM variable (scala.concurrent.stm.Ref) and that will probably do fine. Meanwhile I've temporarily worked around the problem by using reflection to strip away the access limitation from setIdentity and setVersion.

Incidentally. I've had to debug my way through the save call stack a number of times because I keep trying to save ODocuments with fields that expand to complicated object trees. This can go horribly wrong if there is an object somewhere in the tree that OrientDB can't handle, and the stack traces are perfectly opaque: "boom, byte container overflow, game over" :)

Every time I have to do a session like this I have had the same thought - synthesizing the objects and then going through the regular save code is not terribly smart. If the scenario is sufficiently performance sensitive to warrant synthesizing the objects without an extra lookup, then it only makes sense to go through a lower level save API, right? So, if I can retract or modify the issue I'd say, skip this for 2.0, and if there is time and popular demand, later provide a full-control, buyer-beware API that allows setting every field and a completely unsafe/unchecked write without any slowdowns. And setIdentity/setVersion stay protected as they are now? How about this, for an idea? Or, is there perhaps already such an API that I don't know about?

Cheers,

Stefan

stebbi avatar Dec 22 '14 12:12 stebbi

@stebbi we have an internal API for do that, and is exactly what you are saying: buyer-beware

have a look to com.orientechnologies.orient.core.record.ORecordInternal that is exactly the solution to your problem, but be aware we neither guarantee the backward compatibility of this API so each version(also minor maybe) it can change, so if you want use it wrap it somewhere in your code so you don't have to rewrite everything everytime.

and for sure that is better than reflection ;)

if this for you is a fine solution i can close this issue, otherwise we can keep it open for further discussion.

tglman avatar Dec 22 '14 16:12 tglman

Is it enough for you use an internal api? I'm going to close this, if you really need it as public api reopen it.

tglman avatar Dec 30 '14 16:12 tglman

@tglman / @lvca I don't understand why there shouldn't be API support for fully constructing ODocuments, including the identity and version, as the OP described. Consider the use case of a web-based API built on top of OrientDB, in which multiple clients are retrieving/updating objects (which include a serialized version number). If an update is received through the API, shouldn't it be possible to use Orient's version checking by setting the version on an ODocument constructed to represent that update (to ensure that it's not based on an old version, and potentially overwriting new data)?

*edit: include "identity" with version, and mention lvca due to "wontfix" label

buzzkillington avatar Jan 27 '15 17:01 buzzkillington

This is basically the same scenario I was working with - I think exactly the same, from the OrientDB API viewpoint.

On Tuesday, January 27, 2015, buzzkillington [email protected] wrote:

I don't understand why there shouldn't be API support for fully constructing ODocuments, including the version, as the OP described. Consider the use case of a web-based API built on top of OrientDB, in which multiple clients are retrieving/updating objects (which include a serialized version number). If an update is received through the API, shouldn't it be possible to use Orient's version checking by setting the version on an ODocument constructed to represent that update (to ensure that it's not based on an old version, and potentially overwriting new data)?

— Reply to this email directly or view it on GitHub https://github.com/orientechnologies/orientdb/issues/3254#issuecomment-71693576 .

stebbi avatar Jan 28 '15 16:01 stebbi

@lvca / @tglman - can we get this issue (or at least the discussion) re-opened?

buzzkillington avatar Feb 04 '15 19:02 buzzkillington

How about ORecordInternal? I haven't done anything about this yet but that sounded like a solution to me.

On Wed, Feb 4, 2015 at 8:10 PM, buzzkillington [email protected] wrote:

@lvca https://github.com/lvca / @tglman https://github.com/tglman - can we get this issue (or at least the discussion) re-opened?

— Reply to this email directly or view it on GitHub https://github.com/orientechnologies/orientdb/issues/3254#issuecomment-72917905 .

stebbi avatar Feb 08 '15 08:02 stebbi

I disagree with that answer being a solution: using an undocumented/unsupported, internal mechanism is (at best) a kludgy, unsatisfactory workaround. Regarding the other option described above, it seems unnecessary and unreasonable to incur two database hits and perform a manual, client-side version check just to process an update. This should be a public API-supported capability - otherwise, I'd like a more well-reasoned explanation for why, given our use cases, "normal application flow" is defined so narrowly (comment from @tglman above).

buzzkillington avatar Feb 09 '15 20:02 buzzkillington

Give me a try to explain. The logic is following: it's good for overall performance and memory consumption to have just 1 instance for a document in the memory per transaction. If you will try to load/save a document with described way you might have theoretically have 2 java objects for the same document in the memory. And that's might lead to a sequence of problems.

So let me back my previous comments: I think it's definetly should be done in that way as OT guys suggest. And more over: there is almost no performance or usability impact for the client side if you will use methods merge().

PhantomYdn avatar Feb 09 '15 20:02 PhantomYdn

Hmm - how about that then, @tlgman?

I do have to admit that I can't quite follow Ilya's argument. And I did file this as a bug whereas now we're talking about a feature. But either way, perhaps the generalized scenario of receiving every object field value from a JSON API, HTTP push or some equivalent, and blindly stuffing in OrientDB as fastcas possible, is worth keeping around as an option?

I think perhaps the main reason I won't be as decisive on this as @buzzkillington is that I remember what a painful couple of bugs I ran into with mismatched version numbers - no fun to resolve...

On Monday, February 9, 2015, Ilia Naryzhny [email protected] wrote:

Give me a try to explain. The logic is following: it's good for overall performance and memory consumption to have just 1 instance for a document in the memory per transaction. If you will try to load/save a document with described way you might have theoretically have 2 java objects for the same document in the memory. And that's might lead to a sequence of problems.

So let me back my previous comments: I think it's definetly should be done in that way as OT guys suggest. And more over: there is almost no performance or usability impact for the client side if you will use methods merge().

— Reply to this email directly or view it on GitHub https://github.com/orientechnologies/orientdb/issues/3254#issuecomment-73588846 .

stebbi avatar Feb 09 '15 21:02 stebbi