orientdb icon indicating copy to clipboard operation
orientdb copied to clipboard

Distributed: asynchronous inserts ignore unique indexes

Open nethertek opened this issue 12 years ago • 14 comments

Applying a unique index such as

"create index sms_keys ON SMS (type, lang) unique"

is ignored during inserts in distributed asynchronous mode.

nethertek avatar Oct 11 '14 10:10 nethertek

Fixed in 9804c47fe32ce8db81f3743e38ca016ef96b768e and deployed in last 2.0-SNAPSHOT.

lvca avatar Oct 13 '14 13:10 lvca

The issue is again present in version 2.0.9, 2.0.12. Whilst the index is created, it is ignored during insert in distributed mode.

Once duplicates have been inserted, rebuilding the index will cause an exception as expected.

nethertek avatar Jul 21 '15 18:07 nethertek

I cannot reproduce it. Do you have a test case?

lvca avatar Jul 22 '15 23:07 lvca

Creating database [remote:localhost/test] using the storage type [plocal]...
Disconnecting from the database [backnodeee]...OK
Connecting to database [remote:localhost/test] with user 'admin'...OK

DISTRIBUTED CONFIGURATION:
{
  "members": [{
      "id": "57c61537-d5d8-418e-b97a-0867eb5202e3",
      "name": "missouri",
      "startedOn": "2015-07-22 13:04:09",
      "listeners": [{"protocol":"ONetworkProtocolBinary","listen":"50.30.34.105:2424"},{"protocol":"ONetworkProtocolHttpDb","listen":"50.30.34.105:2480"}],
      "databases": []
      },{
      "id": "c72e82e5-d9ef-4571-8b46-c92d82db2abd",
      "name": "tirpitz",
      "startedOn": "2015-07-22 13:06:20",
      "listeners": [{"protocol":"ONetworkProtocolBinary","listen":"148.251.77.75:2424"},{"protocol":"ONetworkProtocolHttpDb","listen":"148.251.77.75:2480"}],
      "databases": []
      }
  ],
  "localName": "_hzInstance_1_orientdb",
  "localId": "c72e82e5-d9ef-4571-8b46-c92d82db2abd"
}
Database created successfully.

Current database is: remote:localhost/test
orientdb {db=test}> create class SMS;

Class created successfully. Total classes in database now: 11

orientdb {db=test}> create property SMS.type string

Property created successfully with id=1

orientdb {db=test}> create property SMS.lang string

Property created successfully with id=2

orientdb {db=test}> create property SMS.source integer

Property created successfully with id=3

orientdb {db=test}> create property SMS.content string

Property created successfully with id=4

orientdb {db=test}> alter property SMS.lang min 2

Property updated successfully

orientdb {db=test}> alter property SMS.lang max 2

Property updated successfully

orientdb {db=test}> create index sms_keys ON SMS (type, lang) unique


Creating index...
Created index successfully with 0 entries in 1.663000 sec(s).


Index created successfully
orientdb {db=test}> 

orientdb {db=test}> insert into sms (type, lang, source, content) values ( 'notify', 'en', 1, 'This is a test');

Inserted record 'SMS#14:0{type:notify,lang:en,source:1,content:This is a test} v1' in 0.014000 sec(s).

orientdb {db=test}> insert into sms (type, lang, source, content) values ( 'notify', 'en', 1, 'This is a test');

Inserted record 'SMS#14:1{type:notify,lang:en,source:1,content:This is a test} v1' in 0.033000 sec(s).

orientdb {db=test}> insert into sms (type, lang, source, content) values ( 'notify', 'en', 1, 'This is a test');

Inserted record 'SMS#14:2{type:notify,lang:en,source:1,content:This is a test} v1' in 0.289000 sec(s).

orientdb {db=test}> insert into sms (type, lang, source, content) values ( 'notify', 'en', 1, 'This is a test');

Inserted record 'SMS#14:3{type:notify,lang:en,source:1,content:This is a test} v1' in 0.005000 sec(s).

orientdb {db=test}> select * from SMS

----+-----+------+------+----+------+--------------
#   |@RID |@CLASS|type  |lang|source|content       
----+-----+------+------+----+------+--------------
0   |#14:0|SMS   |notify|en  |1     |This is a test
1   |#14:1|SMS   |notify|en  |1     |This is a test
2   |#14:2|SMS   |notify|en  |1     |This is a test
3   |#14:3|SMS   |notify|en  |1     |This is a test
----+-----+------+------+----+------+--------------

4 item(s) found. Query executed in 0.007 sec(s).
orientdb {db=test}> rebuild index *


Rebuilding index(es)...
Error: com.orientechnologies.orient.server.distributed.ODistributedException: Error on execution distributed COMMAND

Error: com.orientechnologies.orient.core.index.OIndexException: Error on rebuilding the index for clusters: [sms]

Error: com.orientechnologies.orient.core.storage.ORecordDuplicatedException: Cannot index record #14:1: found duplicated key 'OCompositeKey{keys=[notify, en]}' in index 'sms_keys' previously assigned to the record #14:0 RID=#14:0

orientdb {db=test}> 

nethertek avatar Jul 25 '15 17:07 nethertek

Thanks, working on it...

lvca avatar Jul 30 '15 13:07 lvca

Reproduced with a Java test case.

lvca avatar Jul 30 '15 14:07 lvca

@lvca This is still the case with 2.1.6.

testark avatar Nov 30 '15 23:11 testark

@testark Could you please look at test case https://github.com/orientechnologies/orientdb/blob/ad0e676ffcae25f13e9a67cc58d9a232e6c07fe1/distributed/src/test/java/com/orientechnologies/orient/server/distributed/asynch/AsyncIndexTest.java#L41-L40? It passes with no problems.

lvca avatar Dec 01 '15 15:12 lvca

@lvca In this line

https://github.com/orientechnologies/orientdb/blob/ad0e676ffcae25f13e9a67cc58d9a232e6c07fe1/distributed/src/test/java/com/orientechnologies/orient/server/distributed/asynch/BareBoneBase1ClientTest.java#L26

I see plocal. I am using remote so, believe me this is still the case.

testark avatar Dec 01 '15 18:12 testark

Created new test case (https://github.com/orientechnologies/orientdb/commit/e2b40eec602d213cb4c194d4006bfd081c76679e) with 3 servers and remote and pass...

lvca avatar Dec 01 '15 19:12 lvca

The test case deals with the document API. I'm using the Graph API.

testark avatar Dec 01 '15 20:12 testark

You're right, I was able to reproduce it with 3 nodes, async replication through remote protocol call and graph API that always start a distributed transaction. Working to the fix.

lvca avatar Dec 03 '15 08:12 lvca

@lvca See? :-) I was not trying to be mean or something, just reporting because it is still indeed the case. Glad you can work on that.

testark avatar Dec 03 '15 09:12 testark

Fixed in 2.1.x

lvca avatar Dec 04 '15 16:12 lvca