Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Avoid loading and looking up Locks factory for each database.
Extract factories for various locks construction from CommunityEditionModule. Extract interface for LocksFactory into separate class.
- Loading branch information
1 parent
2c254b7
commit 90b28be
Showing
12 changed files
with
328 additions
and
60 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
community/kernel/src/main/java/org/neo4j/kernel/impl/locking/DynamicLocksFactory.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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* Copyright (c) 2002-2018 "Neo4j," | ||
* Neo4j Sweden AB [http://neo4j.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.impl.locking; | ||
|
||
import org.neo4j.helpers.Service; | ||
|
||
/** | ||
* Factory for lock managers that can be loaded over service loading. | ||
*/ | ||
public abstract class DynamicLocksFactory extends Service implements LocksFactory | ||
{ | ||
public DynamicLocksFactory( String key, String... altKeys ) | ||
{ | ||
super( key, altKeys ); | ||
} | ||
} |
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
30 changes: 30 additions & 0 deletions
30
community/kernel/src/main/java/org/neo4j/kernel/impl/locking/LocksFactory.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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* Copyright (c) 2002-2018 "Neo4j," | ||
* Neo4j Sweden AB [http://neo4j.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.impl.locking; | ||
|
||
import java.time.Clock; | ||
|
||
import org.neo4j.kernel.configuration.Config; | ||
import org.neo4j.storageengine.api.lock.ResourceType; | ||
|
||
public interface LocksFactory | ||
{ | ||
Locks newInstance( Config config, Clock clock, ResourceType[] resourceTypes ); | ||
} |
36 changes: 36 additions & 0 deletions
36
...y/kernel/src/main/java/org/neo4j/kernel/impl/locking/community/CommunityLocksFactory.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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* Copyright (c) 2002-2018 "Neo4j," | ||
* Neo4j Sweden AB [http://neo4j.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.impl.locking.community; | ||
|
||
import java.time.Clock; | ||
|
||
import org.neo4j.kernel.configuration.Config; | ||
import org.neo4j.kernel.impl.locking.Locks; | ||
import org.neo4j.kernel.impl.locking.LocksFactory; | ||
import org.neo4j.storageengine.api.lock.ResourceType; | ||
|
||
public class CommunityLocksFactory implements LocksFactory | ||
{ | ||
@Override | ||
public Locks newInstance( Config config, Clock clock, ResourceType[] resourceTypes ) | ||
{ | ||
return new CommunityLockManger( config, clock ); | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
...rnel/src/test/java/org/neo4j/kernel/impl/locking/community/CommunityLocksFactoryTest.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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* Copyright (c) 2002-2018 "Neo4j," | ||
* Neo4j Sweden AB [http://neo4j.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.impl.locking.community; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import org.neo4j.kernel.configuration.Config; | ||
import org.neo4j.kernel.impl.locking.Locks; | ||
import org.neo4j.kernel.impl.locking.ResourceTypes; | ||
import org.neo4j.time.Clocks; | ||
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.instanceOf; | ||
import static org.junit.jupiter.api.Assertions.assertNotSame; | ||
|
||
class CommunityLocksFactoryTest | ||
{ | ||
|
||
@Test | ||
void createDifferentCommunityLockManagers() | ||
{ | ||
CommunityLocksFactory factory = new CommunityLocksFactory(); | ||
Locks locks1 = factory.newInstance( Config.defaults(), Clocks.systemClock(), ResourceTypes.values() ); | ||
Locks locks2 = factory.newInstance( Config.defaults(), Clocks.systemClock(), ResourceTypes.values() ); | ||
assertNotSame( locks1, locks2 ); | ||
assertThat( locks1, instanceOf( CommunityLockManger.class ) ); | ||
assertThat( locks2, instanceOf( CommunityLockManger.class ) ); | ||
} | ||
} |
72 changes: 72 additions & 0 deletions
72
community/neo4j/src/main/java/org/neo4j/graphdb/factory/EditionLocksFactories.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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* | ||
* Copyright (c) 2002-2018 "Neo4j," | ||
* Neo4j Sweden AB [http://neo4j.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.graphdb.factory; | ||
|
||
import java.time.Clock; | ||
|
||
import org.neo4j.graphdb.factory.module.CommunityEditionModule; | ||
import org.neo4j.helpers.Service; | ||
import org.neo4j.kernel.configuration.Config; | ||
import org.neo4j.kernel.impl.locking.DynamicLocksFactory; | ||
import org.neo4j.kernel.impl.locking.Locks; | ||
import org.neo4j.kernel.impl.locking.LocksFactory; | ||
import org.neo4j.kernel.impl.locking.ResourceTypes; | ||
import org.neo4j.kernel.impl.locking.community.CommunityLocksFactory; | ||
import org.neo4j.kernel.impl.logging.LogService; | ||
|
||
public final class EditionLocksFactories | ||
{ | ||
public static Locks createLockManager( LocksFactory locksFactory, Config config, Clock clock ) | ||
{ | ||
return locksFactory.newInstance( config, clock, ResourceTypes.values() ); | ||
} | ||
|
||
public static LocksFactory createLockFactory( Config config, LogService logging ) | ||
{ | ||
String key = config.get( GraphDatabaseSettings.lock_manager ); | ||
for ( DynamicLocksFactory candidate : Service.load( DynamicLocksFactory.class ) ) | ||
{ | ||
String candidateId = candidate.getKeys().iterator().next(); | ||
if ( key.equals( candidateId ) ) | ||
{ | ||
return candidate; | ||
} | ||
else if ( "".equals( key ) ) | ||
{ | ||
logging.getInternalLog( CommunityEditionModule.class ) | ||
.info( "No locking implementation specified, defaulting to '" + candidateId + "'" ); | ||
return candidate; | ||
} | ||
} | ||
|
||
if ( "community".equals( key ) ) | ||
{ | ||
return new CommunityLocksFactory(); | ||
} | ||
else if ( "".equals( key ) ) | ||
{ | ||
logging.getInternalLog( CommunityEditionModule.class ) | ||
.info( "No locking implementation specified, defaulting to 'community'" ); | ||
return new CommunityLocksFactory(); | ||
} | ||
|
||
throw new IllegalArgumentException( "No lock manager found with the name '" + key + "'." ); | ||
} | ||
} |
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
Oops, something went wrong.