use of org.neo4j.kernel.impl.util.JobScheduler in project neo4j by neo4j.
the class MultiIndexPopulationConcurrentUpdatesIT method launchCustomIndexPopulation.
private void launchCustomIndexPopulation(Map<String, Integer> labelNameIdMap, int propertyId, List<NodeUpdates> updates) throws Exception {
NeoStores neoStores = getNeoStores();
LabelScanStore labelScanStore = getLabelScanStore();
ThreadToStatementContextBridge transactionStatementContextBridge = getTransactionStatementContextBridge();
try (Transaction transaction = embeddedDatabase.beginTx()) {
Statement statement = transactionStatementContextBridge.get();
DynamicIndexStoreView storeView = new DynamicIndexStoreViewWrapper(labelScanStore, LockService.NO_LOCK_SERVICE, neoStores, updates);
SchemaIndexProviderMap providerMap = new DefaultSchemaIndexProviderMap(getSchemaIndexProvider());
JobScheduler scheduler = getJobScheduler();
StatementTokenNameLookup tokenNameLookup = new StatementTokenNameLookup(statement.readOperations());
indexService = IndexingServiceFactory.createIndexingService(Config.empty(), scheduler, providerMap, storeView, tokenNameLookup, getIndexRules(neoStores), NullLogProvider.getInstance(), IndexingService.NO_MONITOR, () -> {
});
indexService.start();
IndexRule[] rules = createIndexRules(labelNameIdMap, propertyId);
indexService.createIndexes(rules);
transaction.success();
}
}
use of org.neo4j.kernel.impl.util.JobScheduler in project neo4j by neo4j.
the class NeoStoreDataSource method buildTransactionLogs.
private NeoStoreTransactionLogModule buildTransactionLogs(File storeDir, Config config, LogProvider logProvider, JobScheduler scheduler, FileSystemAbstraction fileSystemAbstraction, StorageEngine storageEngine, LogEntryReader<ReadableClosablePositionAwareChannel> logEntryReader, SynchronizedArrayIdOrderingQueue legacyIndexTransactionOrdering, TransactionIdStore transactionIdStore, LogVersionRepository logVersionRepository) {
TransactionMetadataCache transactionMetadataCache = new TransactionMetadataCache(100_000);
LogHeaderCache logHeaderCache = new LogHeaderCache(1000);
final PhysicalLogFiles logFiles = new PhysicalLogFiles(storeDir, PhysicalLogFile.DEFAULT_NAME, fileSystemAbstraction);
final PhysicalLogFile logFile = life.add(new PhysicalLogFile(fileSystemAbstraction, logFiles, config.get(GraphDatabaseSettings.logical_log_rotation_threshold), transactionIdStore::getLastCommittedTransactionId, logVersionRepository, physicalLogMonitor, logHeaderCache));
final PhysicalLogFileInformation.LogVersionToTimestamp logInformation = version -> {
LogPosition position = LogPosition.start(version);
try (ReadableLogChannel channel = logFile.getReader(position)) {
LogEntry entry;
while ((entry = logEntryReader.readLogEntry(channel)) != null) {
if (entry instanceof LogEntryStart) {
return entry.<LogEntryStart>as().getTimeWritten();
}
}
}
return -1;
};
final LogFileInformation logFileInformation = new PhysicalLogFileInformation(logFiles, logHeaderCache, transactionIdStore::getLastCommittedTransactionId, logInformation);
if (config.get(GraphDatabaseFacadeFactory.Configuration.ephemeral)) {
config = config.withDefaults(stringMap(GraphDatabaseSettings.keep_logical_logs.name(), "1 files"));
}
String pruningConf = config.get(GraphDatabaseSettings.keep_logical_logs);
LogPruneStrategy logPruneStrategy = fromConfigValue(fs, logFileInformation, logFiles, pruningConf);
final LogPruning logPruning = new LogPruningImpl(logPruneStrategy, logProvider);
final LogRotation logRotation = new LogRotationImpl(monitors.newMonitor(LogRotation.Monitor.class), logFile, databaseHealth);
final TransactionAppender appender = life.add(new BatchingTransactionAppender(logFile, logRotation, transactionMetadataCache, transactionIdStore, legacyIndexTransactionOrdering, databaseHealth));
final LogicalTransactionStore logicalTransactionStore = new PhysicalLogicalTransactionStore(logFile, transactionMetadataCache, logEntryReader);
int txThreshold = config.get(GraphDatabaseSettings.check_point_interval_tx);
final CountCommittedTransactionThreshold countCommittedTransactionThreshold = new CountCommittedTransactionThreshold(txThreshold);
long timeMillisThreshold = config.get(GraphDatabaseSettings.check_point_interval_time);
TimeCheckPointThreshold timeCheckPointThreshold = new TimeCheckPointThreshold(timeMillisThreshold, clock);
CheckPointThreshold threshold = CheckPointThresholds.or(countCommittedTransactionThreshold, timeCheckPointThreshold);
final CheckPointerImpl checkPointer = new CheckPointerImpl(transactionIdStore, threshold, storageEngine, logPruning, appender, databaseHealth, logProvider, tracers.checkPointTracer, ioLimiter, storeCopyCheckPointMutex);
long recurringPeriod = Math.min(timeMillisThreshold, TimeUnit.SECONDS.toMillis(10));
CheckPointScheduler checkPointScheduler = new CheckPointScheduler(checkPointer, scheduler, recurringPeriod, databaseHealth);
life.add(checkPointer);
life.add(checkPointScheduler);
return new NeoStoreTransactionLogModule(logicalTransactionStore, logFileInformation, logFiles, logFile, logRotation, checkPointer, appender, legacyIndexTransactionOrdering);
}
use of org.neo4j.kernel.impl.util.JobScheduler in project neo4j by neo4j.
the class EnterpriseSecurityModule method setup.
@Override
public void setup(Dependencies dependencies) throws KernelException {
Config config = dependencies.config();
Procedures procedures = dependencies.procedures();
LogProvider logProvider = dependencies.logService().getUserLogProvider();
JobScheduler jobScheduler = dependencies.scheduler();
FileSystemAbstraction fileSystem = dependencies.fileSystem();
LifeSupport life = dependencies.lifeSupport();
SecurityLog securityLog = SecurityLog.create(config, dependencies.logService().getInternalLog(GraphDatabaseFacade.class), fileSystem, jobScheduler);
life.add(securityLog);
boolean allowTokenCreate = config.get(SecuritySettings.allow_publisher_create_token);
PredefinedRolesBuilder.setAllowPublisherTokenCreate(allowTokenCreate);
procedures.writerCreateToken(allowTokenCreate);
EnterpriseAuthAndUserManager authManager = newAuthManager(config, logProvider, securityLog, fileSystem, jobScheduler);
life.add(dependencies.dependencySatisfier().satisfyDependency(authManager));
// Register procedures
procedures.registerComponent(SecurityLog.class, (ctx) -> securityLog, false);
procedures.registerComponent(EnterpriseAuthManager.class, ctx -> authManager, false);
procedures.registerComponent(EnterpriseSecurityContext.class, ctx -> asEnterprise(ctx.get(SECURITY_CONTEXT)), true);
if (config.get(SecuritySettings.native_authentication_enabled) || config.get(SecuritySettings.native_authorization_enabled)) {
procedures.registerComponent(EnterpriseUserManager.class, ctx -> authManager.getUserManager(asEnterprise(ctx.get(SECURITY_CONTEXT))), true);
if (config.get(SecuritySettings.auth_providers).size() > 1) {
procedures.registerProcedure(UserManagementProcedures.class, true, Optional.of("%s only applies to native users."));
} else {
procedures.registerProcedure(UserManagementProcedures.class, true);
}
} else {
procedures.registerComponent(EnterpriseUserManager.class, ctx -> EnterpriseUserManager.NOOP, true);
}
procedures.registerProcedure(SecurityProcedures.class, true);
}
use of org.neo4j.kernel.impl.util.JobScheduler in project neo4j by neo4j.
the class UpdatePullerSchedulerTest method skipUpdatePullingSchedulingWithZeroInterval.
@Test
public void skipUpdatePullingSchedulingWithZeroInterval() throws Throwable {
JobScheduler jobScheduler = mock(JobScheduler.class);
UpdatePullerScheduler pullerScheduler = new UpdatePullerScheduler(jobScheduler, NullLogProvider.getInstance(), updatePuller, 0);
// when start puller scheduler - nothing should be scheduled
pullerScheduler.init();
verifyZeroInteractions(jobScheduler, updatePuller);
// should be able shutdown scheduler
pullerScheduler.shutdown();
}
use of org.neo4j.kernel.impl.util.JobScheduler in project neo4j by neo4j.
the class SwitchToSlaveBranchThenCopyTest method updatesPulledAndPullingScheduledOnSwitchToSlave.
@Test
public void updatesPulledAndPullingScheduledOnSwitchToSlave() throws Throwable {
SwitchToSlaveBranchThenCopy switchToSlave = newSwitchToSlaveSpy();
when(fs.fileExists(any(File.class))).thenReturn(true);
JobScheduler jobScheduler = mock(JobScheduler.class);
LifeSupport communicationLife = mock(LifeSupport.class);
URI localhost = getLocalhostUri();
final UpdatePullerScheduler pullerScheduler = new UpdatePullerScheduler(jobScheduler, NullLogProvider.getInstance(), updatePuller, 10L);
when(pullerFactory.createUpdatePullerScheduler(updatePuller)).thenReturn(pullerScheduler);
// emulate lifecycle start call on scheduler
doAnswer(invocationOnMock -> {
pullerScheduler.init();
return null;
}).when(communicationLife).start();
switchToSlave.switchToSlave(communicationLife, localhost, localhost, mock(CancellationRequest.class));
verify(updatePuller).tryPullUpdates();
verify(communicationLife).add(pullerScheduler);
verify(jobScheduler).scheduleRecurring(eq(JobScheduler.Groups.pullUpdates), any(Runnable.class), eq(10L), eq(10L), eq(TimeUnit.MILLISECONDS));
}
Aggregations