Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract separate component from RecordStorageEngine to handle id buff…
…ering, reuse, maintenance etc. Update feature toggles base class in RecordStorageEngine (move to RecordStorageEngine instead of NeoStoreDataSource)
- Loading branch information
1 parent
197d45b
commit 0263234
Showing
8 changed files
with
247 additions
and
74 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
112 changes: 112 additions & 0 deletions
112
...4j/kernel/impl/storageengine/impl/recordstorage/id/BufferedRecordStorageIdController.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,112 @@ | ||
/* | ||
* Copyright (c) 2002-2016 "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.id; | ||
|
||
|
||
import java.util.concurrent.TimeUnit; | ||
import java.util.function.Supplier; | ||
|
||
import org.neo4j.kernel.impl.api.KernelTransactionsSnapshot; | ||
import org.neo4j.kernel.impl.store.id.BufferingIdGeneratorFactory; | ||
import org.neo4j.kernel.impl.store.id.IdGeneratorFactory; | ||
import org.neo4j.kernel.impl.store.id.IdReuseEligibility; | ||
import org.neo4j.kernel.impl.store.id.configuration.IdTypeConfigurationProvider; | ||
import org.neo4j.kernel.impl.util.JobScheduler; | ||
import org.neo4j.kernel.lifecycle.LifecycleAdapter; | ||
|
||
/** | ||
* Storage id controller that provide buffering possibilities to be able so safely free and reuse ids. | ||
* Allows perform clear and maintenance operations over currently buffered set of ids. | ||
* @see BufferingIdGeneratorFactory | ||
*/ | ||
public class BufferedRecordStorageIdController extends LifecycleAdapter implements RecordStorageIdController | ||
{ | ||
|
||
private final BufferingIdGeneratorFactory bufferingIdGeneratorFactory; | ||
private final BufferedIdMaintenanceController idMaintenanceController; | ||
|
||
public BufferedRecordStorageIdController( IdGeneratorFactory idGeneratorFactory, | ||
Supplier<KernelTransactionsSnapshot> transactionsSnapshotSupplier, IdReuseEligibility eligibleForReuse, | ||
IdTypeConfigurationProvider idTypeConfigurationProvider, JobScheduler scheduler ) | ||
{ | ||
bufferingIdGeneratorFactory = new BufferingIdGeneratorFactory( | ||
idGeneratorFactory, transactionsSnapshotSupplier, eligibleForReuse, idTypeConfigurationProvider ); | ||
idMaintenanceController = new BufferedIdMaintenanceController( bufferingIdGeneratorFactory, scheduler ); | ||
} | ||
|
||
public IdGeneratorFactory getIdGeneratorFactory() | ||
{ | ||
return bufferingIdGeneratorFactory; | ||
} | ||
|
||
@Override | ||
public void start() throws Throwable | ||
{ | ||
idMaintenanceController.start(); | ||
} | ||
|
||
@Override | ||
public void stop() throws Throwable | ||
{ | ||
idMaintenanceController.stop(); | ||
} | ||
|
||
@Override | ||
public void clear() | ||
{ | ||
bufferingIdGeneratorFactory.clear(); | ||
} | ||
|
||
@Override | ||
public void maintenance() | ||
{ | ||
idMaintenanceController.maintenance(); | ||
} | ||
|
||
private static class BufferedIdMaintenanceController | ||
{ | ||
private final BufferingIdGeneratorFactory bufferingIdGeneratorFactory; | ||
private final JobScheduler scheduler; | ||
private JobScheduler.JobHandle jobHandle; | ||
|
||
BufferedIdMaintenanceController( BufferingIdGeneratorFactory bufferingIdGeneratorFactory, | ||
JobScheduler scheduler ) | ||
{ | ||
this.bufferingIdGeneratorFactory = bufferingIdGeneratorFactory; | ||
this.scheduler = scheduler; | ||
} | ||
|
||
public void start() throws Throwable | ||
{ | ||
jobHandle = scheduler.scheduleRecurring( JobScheduler.Groups.storageMaintenance, this::maintenance, 1, | ||
TimeUnit.SECONDS ); | ||
} | ||
|
||
public void stop() throws Throwable | ||
{ | ||
jobHandle.cancel( false ); | ||
} | ||
|
||
public void maintenance() | ||
{ | ||
bufferingIdGeneratorFactory.maintenance(); | ||
} | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
...o4j/kernel/impl/storageengine/impl/recordstorage/id/DefaultRecordStorageIdController.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,54 @@ | ||
/* | ||
* Copyright (c) 2002-2016 "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.id; | ||
|
||
|
||
import org.neo4j.kernel.impl.store.id.IdGeneratorFactory; | ||
import org.neo4j.kernel.lifecycle.LifecycleAdapter; | ||
|
||
/** | ||
* Default implementation of {@link RecordStorageIdController}. | ||
* Do not add any additional possibilities or functionality. Wraps provided {@link IdGeneratorFactory}. | ||
*/ | ||
public class DefaultRecordStorageIdController extends LifecycleAdapter implements RecordStorageIdController | ||
{ | ||
|
||
private IdGeneratorFactory idGeneratorFactory; | ||
|
||
public DefaultRecordStorageIdController( IdGeneratorFactory idGeneratorFactory ) | ||
{ | ||
this.idGeneratorFactory = idGeneratorFactory; | ||
} | ||
|
||
public IdGeneratorFactory getIdGeneratorFactory() | ||
{ | ||
return idGeneratorFactory; | ||
} | ||
|
||
@Override | ||
public void clear() | ||
{ | ||
} | ||
|
||
@Override | ||
public void maintenance() | ||
{ | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
.../org/neo4j/kernel/impl/storageengine/impl/recordstorage/id/RecordStorageIdController.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,47 @@ | ||
/* | ||
* Copyright (c) 2002-2016 "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.id; | ||
|
||
|
||
import org.neo4j.kernel.impl.store.id.IdGeneratorFactory; | ||
import org.neo4j.kernel.lifecycle.Lifecycle; | ||
|
||
/** | ||
* Represent abstraction that responsible for any id related operations on a storage engine level: buffering, | ||
* maintenance, clearing, resetting, generation. | ||
*/ | ||
public interface RecordStorageIdController extends Lifecycle | ||
{ | ||
/** | ||
* Retrieve id generation factory for current storage engine | ||
* @return id generation factory | ||
*/ | ||
IdGeneratorFactory getIdGeneratorFactory(); | ||
|
||
/** | ||
* Clear underlying id generation infrastructure (clear buffer of ids to reuse, reset buffers, etc.) | ||
*/ | ||
void clear(); | ||
|
||
/** | ||
* Perform ids related maintenance. | ||
*/ | ||
void maintenance(); | ||
} |
Oops, something went wrong.