Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes as issue with applying index updates to native unique indexes
Given a uniqueness contraint on Foo:bar. If a transaction make changes such that in the end, the constraint is not violated but some intermediate individual step violates the constraint the index would still throw an exception. The reason this happens is that native index validates the uniqueness constraint on every insert (since doing so is for free). Although actually doing so when applying online updates has never been done in the lucene indexes because all that is handled in the kernel layer before committing a transaction anyway. Detecting a conflict while applying updates to a unique index means that there's a bug inside the kernel layer and would result in a kernel panic. Therefore we avoid this problem and do what we do for lucene indexes, namely by not checking conclicts when applying online updates.
- Loading branch information
Showing
6 changed files
with
162 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
.../test/java/org/neo4j/kernel/api/impl/index/AccidentalUniquenessConstraintViolationIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,90 @@ | |||
/* | |||
* Copyright (c) 2002-2018 "Neo Technology," | |||
* Network Engine for Objects in Lund AB [http://neotechnology.com] | |||
* | |||
* This file is part of Neo4j. | |||
* | |||
* Neo4j is free software: you can redistribute it and/or modify | |||
* it under the terms of the GNU General Public License as published by | |||
* the Free Software Foundation, either version 3 of the License, or | |||
* (at your option) any later version. | |||
* | |||
* This program is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
* GNU General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU General Public License | |||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
*/ | |||
package org.neo4j.kernel.api.impl.index; | |||
|
|||
import org.junit.Rule; | |||
import org.junit.Test; | |||
|
|||
import java.util.Map; | |||
|
|||
import org.neo4j.graphdb.Label; | |||
import org.neo4j.graphdb.Node; | |||
import org.neo4j.graphdb.NotFoundException; | |||
import org.neo4j.graphdb.Transaction; | |||
import org.neo4j.test.rule.DatabaseRule; | |||
import org.neo4j.test.rule.ImpermanentDatabaseRule; | |||
|
|||
import static org.junit.Assert.assertEquals; | |||
import static org.junit.Assert.fail; | |||
|
|||
public class AccidentalUniquenessConstraintViolationIT | |||
{ | |||
private static final Label Foo = Label.label( "Foo" ); | |||
private static final String BAR = "bar"; | |||
|
|||
@Rule | |||
public final DatabaseRule db = new ImpermanentDatabaseRule(); | |||
|
|||
@Test | |||
public void shouldApplyChangesWithIntermediateConstraintViolations() throws Exception | |||
{ | |||
// given | |||
try ( Transaction tx = db.beginTx() ) | |||
{ | |||
db.schema().constraintFor( Foo ).assertPropertyIsUnique( BAR ).create(); | |||
tx.success(); | |||
} | |||
Node fourtyTwo; | |||
Node fourtyOne; | |||
try ( Transaction tx = db.beginTx() ) | |||
{ | |||
fourtyTwo = db.createNode( Foo ); | |||
fourtyTwo.setProperty( BAR, 42 ); | |||
fourtyOne = db.createNode( Foo ); | |||
fourtyOne.setProperty( BAR, 41 ); | |||
tx.success(); | |||
} | |||
|
|||
// when | |||
try ( Transaction tx = db.beginTx() ) | |||
{ | |||
Map<String,Object> props = fourtyOne.getAllProperties(); | |||
fourtyOne.delete(); | |||
fourtyTwo.setProperty( BAR, props.get( BAR ) ); | |||
tx.success(); | |||
} | |||
|
|||
// then | |||
try ( Transaction tx = db.beginTx() ) | |||
{ | |||
assertEquals( 41, fourtyTwo.getProperty( BAR ) ); | |||
try | |||
{ | |||
fourtyOne.getProperty( BAR ); | |||
fail( "Should be deleted" ); | |||
} | |||
catch ( NotFoundException e ) | |||
{ | |||
// good | |||
} | |||
tx.success(); | |||
} | |||
} | |||
} |