Skip to content

Commit

Permalink
Fix locking issues
Browse files Browse the repository at this point in the history
  • Loading branch information
pontusmelke committed Mar 14, 2018
1 parent ac1e589 commit 9689e28
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
Expand Up @@ -902,7 +902,7 @@ public ConstraintDescriptor relationshipPropertyExistenceConstraintCreate( Relat
throws SchemaKernelException
{
//Lock
acquireExclusiveRelationshipLock( descriptor.getRelTypeId() );
exclusiveRelationshipTypeLock( descriptor.getRelTypeId() );
ktx.assertOpen();

//verify data integrity
Expand Down Expand Up @@ -1004,6 +1004,11 @@ private void sharedRelationshipTypeLock( long typeId )
ktx.statementLocks().optimistic().acquireShared( ktx.lockTracer(), ResourceTypes.RELATIONSHIP_TYPE, typeId );
}

private void exclusiveRelationshipTypeLock( long typeId )
{
ktx.statementLocks().optimistic().acquireExclusive( ktx.lockTracer(), ResourceTypes.RELATIONSHIP_TYPE, typeId );
}

private void lockRelationshipNodes( long startNodeId, long endNodeId )
{
// Order the locks to lower the risk of deadlocks with other threads creating/deleting rels concurrently
Expand Down
Expand Up @@ -36,7 +36,6 @@
import org.neo4j.graphdb.Transaction;
import org.neo4j.kernel.api.exceptions.ConstraintViolationTransactionFailureException;
import org.neo4j.kernel.api.exceptions.schema.CreateConstraintFailureException;
import org.neo4j.kernel.impl.api.OperationsFacade;
import org.neo4j.kernel.impl.newapi.Operations;
import org.neo4j.test.rule.DatabaseRule;
import org.neo4j.test.rule.EnterpriseDatabaseRule;
Expand All @@ -50,8 +49,10 @@
import static org.junit.runners.Suite.SuiteClasses;
import static org.neo4j.graphdb.Label.label;
import static org.neo4j.graphdb.RelationshipType.withName;
import static org.neo4j.kernel.impl.api.integrationtest.PropertyExistenceConstraintVerificationIT.NodePropertyExistenceExistenceConstrainVerificationIT;
import static org.neo4j.kernel.impl.api.integrationtest.PropertyExistenceConstraintVerificationIT.RelationshipPropertyExistenceExistenceConstrainVerificationIT;
import static org.neo4j.kernel.impl.api.integrationtest.PropertyExistenceConstraintVerificationIT
.NodePropertyExistenceExistenceConstrainVerificationIT;
import static org.neo4j.kernel.impl.api.integrationtest.PropertyExistenceConstraintVerificationIT
.RelationshipPropertyExistenceExistenceConstrainVerificationIT;
import static org.neo4j.test.rule.concurrent.ThreadingRule.waitingWhileIn;

@RunWith( Suite.class )
Expand Down Expand Up @@ -133,7 +134,7 @@ public String offenderCreationMethodName()
@Override
Class<?> getOwner()
{
return OperationsFacade.class;
return Operations.class;
}

}
Expand Down Expand Up @@ -231,7 +232,7 @@ public void shouldFailToCreateConstraintIfConcurrentlyCommittedEntityLacksTheMan
createOffender( db, KEY );

constraintCreation = thread.executeAndAwait( createConstraint(), null,
waitingWhileIn( OperationsFacade.class, constraintCreationMethodName() ),
waitingWhileIn( Operations.class, constraintCreationMethodName() ),
WAIT_TIMEOUT_SECONDS, SECONDS );

tx.success();
Expand Down

0 comments on commit 9689e28

Please sign in to comment.