Skip to content

Commit

Permalink
Split global schema lock
Browse files Browse the repository at this point in the history
Split global schema lock into independent label and relationship type locks
that will be used depending from type of index, constraint etc.
Completely remove SCHEMA resource from type of resources that can be locked.

Slaves in ha now will take labels and rel type locks on master exactly like
for nodes and relationship locks.

This commit performs split in kernel/ha code.
Cypher code not updated as part of this commit.
  • Loading branch information
MishaDemianenko committed Jul 17, 2017
1 parent bedadeb commit 29fe48d
Show file tree
Hide file tree
Showing 30 changed files with 273 additions and 463 deletions.
Expand Up @@ -586,11 +586,6 @@ public enum LabelIndex
public static final Setting<String> procedure_unrestricted = public static final Setting<String> procedure_unrestricted =
setting( "dbms.security.procedures.unrestricted", Settings.STRING, "" ); setting( "dbms.security.procedures.unrestricted", Settings.STRING, "" );


@Description( "Whether or not to release the exclusive schema lock is while building uniqueness constraints index" )
@Internal
public static final Setting<Boolean> release_schema_lock_while_building_constraint = setting(
"unsupported.dbms.schema.release_lock_while_building_constraint", BOOLEAN, FALSE );

@Description( "A list of procedures (comma separated) that are to be loaded. " + @Description( "A list of procedures (comma separated) that are to be loaded. " +
"The list may contain both fully-qualified procedure names, and partial names with the wildcard '*'. " + "The list may contain both fully-qualified procedure names, and partial names with the wildcard '*'. " +
"If this setting is left empty no procedures will be loaded." ) "If this setting is left empty no procedures will be loaded." )
Expand Down
Expand Up @@ -725,11 +725,8 @@ private NeoStoreKernelModule buildKernel( TransactionAppender appender,
*/ */
Supplier<KernelAPI> kernelProvider = () -> kernelModule.kernelAPI(); Supplier<KernelAPI> kernelProvider = () -> kernelModule.kernelAPI();


boolean releaseSchemaLockWhenBuildingConstratinIndexes = ConstraintIndexCreator constraintIndexCreator = new ConstraintIndexCreator( kernelProvider, indexingService,
config.get( GraphDatabaseSettings.release_schema_lock_while_building_constraint ); propertyAccessor );
ConstraintIndexCreator constraintIndexCreator =
new ConstraintIndexCreator( kernelProvider, indexingService, propertyAccessor,
releaseSchemaLockWhenBuildingConstratinIndexes );


LegacyIndexStore legacyIndexStore = new LegacyIndexStore( config, LegacyIndexStore legacyIndexStore = new LegacyIndexStore( config,
indexConfigStore, kernelProvider, legacyIndexProviderLookup ); indexConfigStore, kernelProvider, legacyIndexProviderLookup );
Expand Down
Expand Up @@ -22,6 +22,8 @@
import java.util.Arrays; import java.util.Arrays;


import org.neo4j.kernel.api.TokenNameLookup; import org.neo4j.kernel.api.TokenNameLookup;
import org.neo4j.kernel.impl.locking.ResourceTypes;
import org.neo4j.storageengine.api.lock.ResourceType;


public class LabelSchemaDescriptor implements SchemaDescriptor, LabelSchemaSupplier public class LabelSchemaDescriptor implements SchemaDescriptor, LabelSchemaSupplier
{ {
Expand Down Expand Up @@ -58,6 +60,18 @@ public int getLabelId()
return labelId; return labelId;
} }


@Override
public int keyId()
{
return getLabelId();
}

@Override
public ResourceType keyType()
{
return ResourceTypes.LABEL;
}

@Override @Override
public int[] getPropertyIds() public int[] getPropertyIds()
{ {
Expand Down
Expand Up @@ -22,6 +22,8 @@
import java.util.Arrays; import java.util.Arrays;


import org.neo4j.kernel.api.TokenNameLookup; import org.neo4j.kernel.api.TokenNameLookup;
import org.neo4j.kernel.impl.locking.ResourceTypes;
import org.neo4j.storageengine.api.lock.ResourceType;


public class RelationTypeSchemaDescriptor implements SchemaDescriptor public class RelationTypeSchemaDescriptor implements SchemaDescriptor
{ {
Expand Down Expand Up @@ -64,6 +66,18 @@ public int[] getPropertyIds()
return propertyIds; return propertyIds;
} }


@Override
public int keyId()
{
return getRelTypeId();
}

@Override
public ResourceType keyType()
{
return ResourceTypes.RELATIONSHIP_TYPE;
}

public int getPropertyId() public int getPropertyId()
{ {
if ( propertyIds.length != 1 ) if ( propertyIds.length != 1 )
Expand Down
Expand Up @@ -22,6 +22,8 @@
import java.util.function.Predicate; import java.util.function.Predicate;


import org.neo4j.kernel.api.TokenNameLookup; import org.neo4j.kernel.api.TokenNameLookup;
import org.neo4j.kernel.impl.locking.ResourceTypes;
import org.neo4j.storageengine.api.lock.ResourceType;


/** /**
* Internal representation of one schema unit, for example a label-property pair. * Internal representation of one schema unit, for example a label-property pair.
Expand Down Expand Up @@ -71,6 +73,24 @@ public interface SchemaDescriptor
*/ */
int[] getPropertyIds(); int[] getPropertyIds();


/**
* Id of underlying schema descriptor key.
* Key is part of schema unit that determines which resources with specified properties are applicable.
* So far {@link ResourceTypes#LABEL label} and {@link ResourceTypes#RELATIONSHIP_TYPE relationship type}
* are supported as keys types.
* @return id of underlying key
*/
int keyId();

/**
* Type of underlying schema descriptor key.
* Key is part of schema unit that determines which resources with specified properties are applicable.
* So far {@link ResourceTypes#LABEL label} and {@link ResourceTypes#RELATIONSHIP_TYPE relationship type}
* are supported as keys types.
* @return type of underlying key
*/
ResourceType keyType();

/** /**
* Create a predicate that checks whether a schema descriptor Supplier supplies the given schema descriptor. * Create a predicate that checks whether a schema descriptor Supplier supplies the given schema descriptor.
* @param descriptor The schema descriptor to check equality with. * @param descriptor The schema descriptor to check equality with.
Expand Down
Expand Up @@ -70,6 +70,7 @@
import org.neo4j.kernel.impl.constraints.ConstraintSemantics; import org.neo4j.kernel.impl.constraints.ConstraintSemantics;
import org.neo4j.kernel.impl.locking.LockTracer; import org.neo4j.kernel.impl.locking.LockTracer;
import org.neo4j.kernel.impl.locking.Locks; import org.neo4j.kernel.impl.locking.Locks;
import org.neo4j.kernel.impl.locking.ResourceTypes;
import org.neo4j.storageengine.api.Direction; import org.neo4j.storageengine.api.Direction;
import org.neo4j.storageengine.api.NodeItem; import org.neo4j.storageengine.api.NodeItem;
import org.neo4j.storageengine.api.PropertyItem; import org.neo4j.storageengine.api.PropertyItem;
Expand Down Expand Up @@ -153,6 +154,8 @@ public Value nodeSetProperty( KernelStatement state, long nodeId, int propertyKe
nodeSchemaMatcher.onMatchingSchema( state, uniquenessConstraints, node, propertyKeyId, nodeSchemaMatcher.onMatchingSchema( state, uniquenessConstraints, node, propertyKeyId,
( constraint, propertyIds ) -> ( constraint, propertyIds ) ->
{ {
state.locks().optimistic().acquireShared( state.lockTracer(), ResourceTypes.LABEL,
constraint.schema().getLabelId() );


if ( propertyIds.contains( propertyKeyId ) ) if ( propertyIds.contains( propertyKeyId ) )
{ {
Expand Down
Expand Up @@ -47,6 +47,7 @@ public KernelSchemaStateStore( LogProvider logProvider )
} }


@SuppressWarnings( "unchecked" ) @SuppressWarnings( "unchecked" )
@Override
public <K, V> V get( K key ) public <K, V> V get( K key )
{ {
lock.readLock().lock(); lock.readLock().lock();
Expand Down Expand Up @@ -93,6 +94,7 @@ public <K, V> V getOrCreate( K key, Function<K,V> creator )
} }
} }


@Override
public void replace( Map<Object,Object> replacement ) public void replace( Map<Object,Object> replacement )
{ {
lock.writeLock().lock(); lock.writeLock().lock();
Expand All @@ -106,6 +108,7 @@ public void replace( Map<Object,Object> replacement )
} }
} }


@Override
public <K, V> void apply( Map<K,V> updates ) public <K, V> void apply( Map<K,V> updates )
{ {
lock.writeLock().lock(); lock.writeLock().lock();
Expand All @@ -119,6 +122,7 @@ public <K, V> void apply( Map<K,V> updates )
} }
} }


@Override
public void clear() public void clear()
{ {
lock.writeLock().lock(); lock.writeLock().lock();
Expand Down

0 comments on commit 29fe48d

Please sign in to comment.