Binary Protocol: recordPos not returned on INSERT
When performing INSERT operations, the recordPos is not returned (OrientDB 2.1.4):
2015-10-25 16:41:27:448 INFO /127.0.0.1:40719 - Read 124 bytes: 1com.orientechnologies.orient.core.sql.OCommandSQL?INSERT INTO Post (content, timestamp) VALUES ('kj', 1445791287) [OChannelBinaryServer]
2015-10-25 16:41:27:490 FINE **Created record #28:7** v.1 size=25 bytes [OLocalPaginatedStorage]
2015-10-25 16:41:27:491 INFO /127.0.0.1:40719 - Writing byte (1 byte): 0 [OChannelBinaryServer]
2015-10-25 16:41:27:491 INFO /127.0.0.1:40719 - Writing int (4 bytes): 4 [OChannelBinaryServer]
2015-10-25 16:41:27:491 INFO /127.0.0.1:40719 - Writing byte (1 byte): 114 [OChannelBinaryServer]
2015-10-25 16:41:27:491 INFO /127.0.0.1:40719 - Writing short (2 bytes): 0 [OChannelBinaryServer]
2015-10-25 16:41:27:491 INFO /127.0.0.1:40719 - Writing byte (1 byte): 100 [OChannelBinaryServer]
2015-10-25 16:41:27:491 INFO /127.0.0.1:40719 - **Writing short (2 bytes): 28** [OChannelBinaryServer]
2015-10-25 16:41:27:491 INFO /127.0.0.1:40719 - **Writing long (8 bytes): -1** [OChannelBinaryServer]
hi @nethertek
what do you mean not returned?
Are you using JAVA API?
Hi @maggiolo00
No, we are directly interfacing with the Binary Protocol on Port 2424. Whilst the ClusterID is correctly returned, we get -1 for the recordPos.
is there any way to get the last inserted RID with a select or similar in the meantime?
hi @nethertek is there a way to replicate it? i just tried with java api and everything went as expected
@nethertek the default behavior is to return the last insert rid, and we are not able to reproduce your problem.
@all
The problem appears twofold.
When we run in single mode, the information is returned correctly, however orientdb seems to increment the ClusterID instead of recordPos with each insert:
2015-10-26 19:09:06:273 INFO {db=backnode} /127.0.0.1:57690 - Read 124 bytes: 1com.orientechnologies.orient.core.sql.OCommandSQL?INSERT INTO Post (content, timestamp) VALUES ('sd', 1445886546) [OChannelBinaryServer] 2015-10-26 19:09:06:275 INFO {db=backnode} /127.0.0.1:57690 - Writing byte (1 byte): 0 [OChannelBinaryServer] 2015-10-26 19:09:06:275 INFO {db=backnode} /127.0.0.1:57690 - Writing int (4 bytes): 10 [OChannelBinaryServer] 2015-10-26 19:09:06:275 INFO {db=backnode} /127.0.0.1:57690 - Writing byte (1 byte): 114 [OChannelBinaryServer] 2015-10-26 19:09:06:275 INFO {db=backnode} /127.0.0.1:57690 - Writing short (2 bytes): 0 [OChannelBinaryServer] 2015-10-26 19:09:06:275 INFO {db=backnode} /127.0.0.1:57690 - Writing byte (1 byte): 100 [OChannelBinaryServer] 2015-10-26 19:09:06:275 INFO {db=backnode} /127.0.0.1:57690 - Writing short (2 bytes): 39 [OChannelBinaryServer] 2015-10-26 19:09:06:275 INFO {db=backnode} /127.0.0.1:57690 - Writing long (8 bytes): 0 [OChannelBinaryServer]
orientdb {db=backnode}> select from Post
# |@RID |@CLASS|content|timestamp
----+-----+------+-------+----------
0 |#28:0|Post |sd |1445886453
1 |#29:0|Post |sd |1445886462
2 |#39:0|Post |sd |1445886546
----+-----+------+-------+----------
In distributed mode , orientdb updates the recordPos, but returns -1
2015-10-26 19:14:02:480 INFO /127.0.0.1:57729 - Read 124 bytes: 1com.orientechnologies.orient.core.sql.OCommandSQL?INSERT INTO Post (content, timestamp) VALUES ('sd', 1445886842) [OChannelBinaryServer] 2015-10-26 19:14:02:532 INFO /127.0.0.1:57729 - Writing byte (1 byte): 0 [OChannelBinaryServer] 2015-10-26 19:14:02:532 INFO /127.0.0.1:57729 - Writing int (4 bytes): 2 [OChannelBinaryServer] 2015-10-26 19:14:02:532 INFO /127.0.0.1:57729 - Writing byte (1 byte): 114 [OChannelBinaryServer] 2015-10-26 19:14:02:533 INFO /127.0.0.1:57729 - Writing short (2 bytes): 0 [OChannelBinaryServer] 2015-10-26 19:14:02:533 INFO /127.0.0.1:57729 - Writing byte (1 byte): 100 [OChannelBinaryServer] 2015-10-26 19:14:02:533 INFO /127.0.0.1:57729 - Writing short (2 bytes): 28 [OChannelBinaryServer] 2015-10-26 19:14:02:533 INFO /127.0.0.1:57729 - Writing long (8 bytes): -1 [OChannelBinaryServer]
# |@RID |@CLASS|content|timestamp
----+-----+------+-------+----------
0 |#28:0|Post |sd |1445886453
1 |#28:1|Post |sd |1445886842
2 |#29:0|Post |sd |1445886462
3 |#39:0|Post |sd |1445886546
----+-----+------+-------+----------
So please try to reproduce the problem in distributed mode with asynchronous enabled. It is also unclear to me why the cluster id is incremented in single mode, perhaps because the database was initialized as a distributed database?
@nethertek ok so in distributed mode you get -1 in recordPos, we will try to reproduce it.
For cluster yes should be the distributed mode.
Hi @nethertek,
The cause of the negative id is due to the asynchronous mode, because the server doesn't wait for the operation to be done, so it cannot know the full id, the only way to get the id is do a query after.
That's ridiculous... Since it's inserting into the local cluster, it is well aware of the recordPos. The replications needs to be asynchronous, not the INSERT.
Furthermore, there is no method to retrieve the last RID.
How on earth can we deploy OrientDB to production like this?
@nethertek I think there is a misunderstanding here. The cluster position is known even during async replication. So there is something wrong in the management of the returned value. Please let me investigate on it.
You were right: the clusterPos wasn't returned correctly in case of async replication. Fixed in 2.1.x and develop branches.
Written also a test case for that.