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

[Bug] Java Api .command(query) result in a temporary RID #8949

Closed
matanshukry opened this issue Jul 8, 2019 · 15 comments
Closed

[Bug] Java Api .command(query) result in a temporary RID #8949

matanshukry opened this issue Jul 8, 2019 · 15 comments
Assignees
Labels
Milestone

Comments

@matanshukry
Copy link
Contributor

OrientDB Version: 3.0.21

Java Version: 1.8.0_211

OS: Windows 10

Expected behavior

The result of a create query will include a positive (real) RID

Actual behavior

The result of a create query includes a negative (temporary) RID

Steps to reproduce

// ODatabase session = ... // obtain a session to the database
OResultSet result = session.command("CREATE VERTEX User SET name=\"bla1\"");
// RID: result.next().getRecord().get().getIdentity()
@wolf4ood
Copy link
Member

wolf4ood commented Jul 8, 2019

Hi @matanshukry

did you begin a transaction before the command?

session.begin();

Thanks

@matanshukry
Copy link
Contributor Author

@wolf4ood Yup. Also doing .commit() after, but that's after I'm getting the recordid anyway.

@wolf4ood
Copy link
Member

wolf4ood commented Jul 8, 2019

Hi @matanshukry

this works for me

@Test
  public void testTx() {

    OrientDB orientDB = new OrientDB("embedded:", OrientDBConfig.defaultConfig());

    orientDB.createIfNotExists("test", ODatabaseType.MEMORY);

    ODatabaseSession database = orientDB.open("test", "admin", "admin");

    database.begin();

    OVertex vertex;

    try (OResultSet resultSet = database.command("create vertex V set name = 'Test'")) {
      vertex = resultSet.next().getVertex().get();
    }

    database.commit();

    Assert.assertTrue(vertex.getIdentity().isPersistent());

  }

you should get the identity after the commit, since new records in tx have temporary rids

Let me know if this helps

Thanks

@wolf4ood wolf4ood self-assigned this Jul 8, 2019
@matanshukry
Copy link
Contributor Author

@wolf4ood I am getting the identity before the .commit(), which seems to be issue. Although I'm using breakpoints, and although I'm getting a temporary identity at that point, if I'll query the database using another session/console, I can see the new row with a persistent identity. Hence it exist, so why can't I access it?

Also, my current flow, which I believe is a common flow, is to convert the result of a db operation immediately when I have the result. Hence:
(1) session.begin()
(2) userA = findUserBy..(...)
(3) userB = createUser..(..)
(4) session.commit()

where each method such as findUserBy/createUser would go something like this:
(1) OResult result = session.command(query, args)
(2) User user = convertFromDb(result);

@matanshukry
Copy link
Contributor Author

@wolf4ood Actually, it seems it doesn't work after the .commit() either. What I tried after your comment:

(1) session.begin()
(2) OResult result = session.command(query, args);
(3) this.user = convertResultToUser(result)
(4) this.savedResult = result
(5) session.commit()
(6) session.close()
(7) result.getRecord().map(ORecord::getIdentity).filter(ORID::isPersistent).orElse(null);

Line (7) is null. I can debug and see cluster position is still negative (-2).

@wolf4ood
Copy link
Member

wolf4ood commented Jul 9, 2019

Hi @matanshukry

that's strange. Do you have a test case to reproduce this?

@wolf4ood
Copy link
Member

wolf4ood commented Jul 9, 2019

Oh i was testing using embedded and works fine. By switching to remote it remains negative

Let me check

@matanshukry
Copy link
Contributor Author

cool thx. I tried checking by saving OResultSet instead of just OResult, and even calling .next() only after the .commit(), all the same. Note it only happens when i'm calling .begin() and .commit()

@wolf4ood
Copy link
Member

wolf4ood commented Jul 9, 2019

@matanshukry

yes because with begin and commit there is a server side transaction in progress. My understanding that at commit time there is no rebinding of final rids, which happens in embedded.

@matanshukry
Copy link
Contributor Author

matanshukry commented Jul 9, 2019

@wolf4ood Yeah I realized that too now. Just to clarify though, when you're saying "my understanding" - are you referring to how things work, or how things should work?

Also, I do notice ORecordAbstract.setIdentity() is called twice when using .begin and .commit().
Although the second time is called before the .commit(), in here: https://github.com/orientechnologies/orientdb/blob/develop/client/src/main/java/com/orientechnologies/orient/core/db/document/ODatabaseDocumentRemote.java#L375

According to OTransactionOptimisticClient.replaceContent(), it also looks like it's expecting a new non-temporary rid at that moment.

@wolf4ood
Copy link
Member

wolf4ood commented Jul 9, 2019

Hi @matanshukry

my understanding from a debug session is that the rebind is not working properly.
After commit the OVertex should contain the final rid

@wolf4ood
Copy link
Member

wolf4ood commented Jul 9, 2019

Hi @matanshukry

i was able to fix it. I'm running the test and if passes i will push it

Thanks

@wolf4ood wolf4ood added the bug label Jul 9, 2019
@wolf4ood wolf4ood added this to the 3.0.22 milestone Jul 9, 2019
wolf4ood added a commit that referenced this issue Jul 9, 2019
@wolf4ood
Copy link
Member

wolf4ood commented Jul 9, 2019

Hi @matanshukry

i've just pushed a fix. it will be available in the next release 3.0.22

Thanks

@matanshukry
Copy link
Contributor Author

@wolf4ood awesome, cool!

Since it's a client code It is a bit more difficult for me to get an updated code for it, so I'll have to wait. do you know when is 3.0.22 planned to be released?

@wolf4ood
Copy link
Member

wolf4ood commented Jul 9, 2019

@matanshukry

not yet sure when. Probably next week

Thanks

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

2 participants