Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Heavily reduces contention on generating ids
The main idea is to have batching id generators local to each transaction instance (which is pooled). This batching sits in between store and typical creators of records at commit time and hands out ids, grabbing batches of ids off of the stores. On clean shutdown any excess ids remaining unused will be freed back into the store before closing. In scenarios where there are many concurrent transactions committing data, where they all co-operatively force the log then this id generator contention is the single biggest one. With these changes this contention is basically removed entirely. The default batch size is 20, which reduces contention dramatically and should be a good value for most scenarios. The value is however controllable with a database setting.
- Loading branch information
Showing
50 changed files
with
1,132 additions
and
397 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
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
92 changes: 92 additions & 0 deletions
92
...o4j/kernel/impl/storageengine/impl/recordstorage/RecordStorageCommandCreationContext.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,92 @@ | |||
/* | |||
* Copyright (c) 2002-2017 "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.impl.storageengine.impl.recordstorage; | |||
|
|||
import org.neo4j.kernel.impl.store.NeoStores; | |||
import org.neo4j.kernel.impl.store.StandardDynamicRecordAllocator; | |||
import org.neo4j.kernel.impl.store.StoreType; | |||
import org.neo4j.kernel.impl.store.id.RenewableBatchIdSequences; | |||
import org.neo4j.kernel.impl.transaction.state.IntegrityValidator; | |||
import org.neo4j.kernel.impl.transaction.state.Loaders; | |||
import org.neo4j.kernel.impl.transaction.state.PropertyCreator; | |||
import org.neo4j.kernel.impl.transaction.state.PropertyDeleter; | |||
import org.neo4j.kernel.impl.transaction.state.PropertyTraverser; | |||
import org.neo4j.kernel.impl.transaction.state.RecordChangeSet; | |||
import org.neo4j.kernel.impl.transaction.state.RelationshipCreator; | |||
import org.neo4j.kernel.impl.transaction.state.RelationshipDeleter; | |||
import org.neo4j.kernel.impl.transaction.state.RelationshipGroupGetter; | |||
import org.neo4j.kernel.impl.transaction.state.TransactionRecordState; | |||
import org.neo4j.storageengine.api.CommandCreationContext; | |||
import org.neo4j.storageengine.api.lock.ResourceLocker; | |||
|
|||
/** | |||
* Holds commit data structures for creating records in a {@link NeoStores}. | |||
*/ | |||
public class RecordStorageCommandCreationContext implements CommandCreationContext | |||
{ | |||
private final NeoStores neoStores; | |||
private final Loaders loaders; | |||
private final RelationshipCreator relationshipCreator; | |||
private final RelationshipDeleter relationshipDeleter; | |||
private final PropertyCreator propertyCreator; | |||
private final PropertyDeleter propertyDeleter; | |||
private final RenewableBatchIdSequences idBatches; | |||
|
|||
RecordStorageCommandCreationContext( NeoStores neoStores, int denseNodeThreshold, int idBatchSize ) | |||
{ | |||
this.neoStores = neoStores; | |||
this.idBatches = new RenewableBatchIdSequences( neoStores, idBatchSize ); | |||
|
|||
this.loaders = new Loaders( neoStores ); | |||
RelationshipGroupGetter relationshipGroupGetter = | |||
new RelationshipGroupGetter( idBatches.idGenerator( StoreType.RELATIONSHIP_GROUP ) ); | |||
this.relationshipCreator = new RelationshipCreator( relationshipGroupGetter, denseNodeThreshold ); | |||
PropertyTraverser propertyTraverser = new PropertyTraverser(); | |||
this.propertyDeleter = new PropertyDeleter( propertyTraverser ); | |||
this.relationshipDeleter = new RelationshipDeleter( relationshipGroupGetter, propertyDeleter ); | |||
this.propertyCreator = new PropertyCreator( | |||
new StandardDynamicRecordAllocator( idBatches.idGenerator( StoreType.PROPERTY_STRING ), | |||
neoStores.getPropertyStore().getStringStore().getRecordDataSize() ), | |||
new StandardDynamicRecordAllocator( idBatches.idGenerator( StoreType.PROPERTY_ARRAY ), | |||
neoStores.getPropertyStore().getArrayStore().getRecordDataSize() ), | |||
idBatches.idGenerator( StoreType.PROPERTY ), | |||
propertyTraverser ); | |||
} | |||
|
|||
public long nextId( StoreType storeType ) | |||
{ | |||
return idBatches.nextId( storeType ); | |||
} | |||
|
|||
@Override | |||
public void close() | |||
{ | |||
this.idBatches.close(); | |||
} | |||
|
|||
public TransactionRecordState createTransactionRecordState( IntegrityValidator integrityValidator, long lastTransactionIdWhenStarted, | |||
ResourceLocker locks ) | |||
{ | |||
RecordChangeSet recordChangeSet = new RecordChangeSet( loaders ); | |||
return new TransactionRecordState( neoStores, integrityValidator, | |||
recordChangeSet, lastTransactionIdWhenStarted, locks, | |||
relationshipCreator, relationshipDeleter, propertyCreator, propertyDeleter ); | |||
} | |||
} |
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
Oops, something went wrong.