Problem using Clean Up History Async

Hi,

I’m having some trouble when I use historyService.cleanUpHistoryAsync(true).

In my configuration, Hystory Time To Live is marked with P2D.

But I’m getting the following error:

2019-04-12 09:30:57.488 ERROR 1 --- [ool-3-thread-11] org.camunda.bpm.engine.context           : ENGINE-16004 Exception while closing command context: null

java.lang.NullPointerException: null
	at org.camunda.bpm.engine.impl.jobexecutor.historycleanup.HistoryCleanupBatch.recordValue(HistoryCleanupBatch.java:88) ~[camunda-engine-7.8.0.jar!/:7.8.0]
	at org.camunda.bpm.engine.impl.jobexecutor.historycleanup.HistoryCleanupBatch.performCleanup(HistoryCleanupBatch.java:69) ~[camunda-engine-7.8.0.jar!/:7.8.0]
	at org.camunda.bpm.engine.impl.jobexecutor.historycleanup.HistoryCleanupJobHandler.execute(HistoryCleanupJobHandler.java:40) ~[camunda-engine-7.8.0.jar!/:7.8.0]
	at org.camunda.bpm.engine.impl.jobexecutor.historycleanup.HistoryCleanupJobHandler.execute(HistoryCleanupJobHandler.java:16) ~[camunda-engine-7.8.0.jar!/:7.8.0]
	at org.camunda.bpm.engine.impl.persistence.entity.JobEntity.execute(JobEntity.java:129) ~[camunda-engine-7.8.0.jar!/:7.8.0]
	at org.camunda.bpm.engine.impl.cmd.ExecuteJobsCmd.execute(ExecuteJobsCmd.java:99) ~[camunda-engine-7.8.0.jar!/:7.8.0]
	at org.camunda.bpm.engine.impl.cmd.ExecuteJobsCmd.execute(ExecuteJobsCmd.java:36) ~[camunda-engine-7.8.0.jar!/:7.8.0]
	at org.camunda.bpm.engine.impl.interceptor.CommandExecutorImpl.execute(CommandExecutorImpl.java:24) ~[camunda-engine-7.8.0.jar!/:7.8.0]
	at org.camunda.bpm.engine.impl.interceptor.CommandContextInterceptor.execute(CommandContextInterceptor.java:104) ~[camunda-engine-7.8.0.jar!/:7.8.0]
	at org.camunda.bpm.engine.spring.SpringTransactionInterceptor$1.doInTransaction(SpringTransactionInterceptor.java:42) [camunda-engine-spring-7.8.0.jar!/:7.8.0]
	at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:140) [spring-tx-5.0.6.RELEASE.jar!/:5.0.6.RELEASE]
	at org.camunda.bpm.engine.spring.SpringTransactionInterceptor.execute(SpringTransactionInterceptor.java:40) [camunda-engine-spring-7.8.0.jar!/:7.8.0]
	at org.camunda.bpm.engine.impl.interceptor.ProcessApplicationContextInterceptor.execute(ProcessApplicationContextInterceptor.java:66) [camunda-engine-7.8.0.jar!/:7.8.0]
	at org.camunda.bpm.engine.impl.interceptor.LogInterceptor.execute(LogInterceptor.java:30) [camunda-engine-7.8.0.jar!/:7.8.0]
	at org.camunda.bpm.engine.impl.jobexecutor.ExecuteJobHelper.executeJob(ExecuteJobHelper.java:36) [camunda-engine-7.8.0.jar!/:7.8.0]
	at org.camunda.bpm.engine.impl.jobexecutor.ExecuteJobHelper.executeJob(ExecuteJobHelper.java:29) [camunda-engine-7.8.0.jar!/:7.8.0]
	at org.camunda.bpm.engine.impl.jobexecutor.ExecuteJobsRunnable.executeJob(ExecuteJobsRunnable.java:88) [camunda-engine-7.8.0.jar!/:7.8.0]
	at org.camunda.bpm.engine.impl.jobexecutor.ExecuteJobsRunnable.run(ExecuteJobsRunnable.java:57) [camunda-engine-7.8.0.jar!/:7.8.0]
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [na:1.8.0_151]
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [na:1.8.0_151]
	at java.lang.Thread.run(Thread.java:748) [na:1.8.0_151]

2019-04-12 09:30:57.525  WARN 1 --- [ool-3-thread-11] org.camunda.bpm.engine.jobexecutor       : ENGINE-14006 Exception while executing job 286519c5-56e3-11e9-aad6-0a580a4d1372: 

java.lang.NullPointerException: null
	at org.camunda.bpm.engine.impl.jobexecutor.historycleanup.HistoryCleanupBatch.recordValue(HistoryCleanupBatch.java:88) ~[camunda-engine-7.8.0.jar!/:7.8.0]
	at org.camunda.bpm.engine.impl.jobexecutor.historycleanup.HistoryCleanupBatch.performCleanup(HistoryCleanupBatch.java:69) ~[camunda-engine-7.8.0.jar!/:7.8.0]
	at org.camunda.bpm.engine.impl.jobexecutor.historycleanup.HistoryCleanupJobHandler.execute(HistoryCleanupJobHandler.java:40) ~[camunda-engine-7.8.0.jar!/:7.8.0]
	at org.camunda.bpm.engine.impl.jobexecutor.historycleanup.HistoryCleanupJobHandler.execute(HistoryCleanupJobHandler.java:16) ~[camunda-engine-7.8.0.jar!/:7.8.0]
	at org.camunda.bpm.engine.impl.persistence.entity.JobEntity.execute(JobEntity.java:129) ~[camunda-engine-7.8.0.jar!/:7.8.0]
	at org.camunda.bpm.engine.impl.cmd.ExecuteJobsCmd.execute(ExecuteJobsCmd.java:99) ~[camunda-engine-7.8.0.jar!/:7.8.0]
	at org.camunda.bpm.engine.impl.cmd.ExecuteJobsCmd.execute(ExecuteJobsCmd.java:36) ~[camunda-engine-7.8.0.jar!/:7.8.0]
	at org.camunda.bpm.engine.impl.interceptor.CommandExecutorImpl.execute(CommandExecutorImpl.java:24) ~[camunda-engine-7.8.0.jar!/:7.8.0]
	at org.camunda.bpm.engine.impl.interceptor.CommandContextInterceptor.execute(CommandContextInterceptor.java:104) ~[camunda-engine-7.8.0.jar!/:7.8.0]
	at org.camunda.bpm.engine.spring.SpringTransactionInterceptor$1.doInTransaction(SpringTransactionInterceptor.java:42) ~[camunda-engine-spring-7.8.0.jar!/:7.8.0]
	at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:140) ~[spring-tx-5.0.6.RELEASE.jar!/:5.0.6.RELEASE]
	at org.camunda.bpm.engine.spring.SpringTransactionInterceptor.execute(SpringTransactionInterceptor.java:40) ~[camunda-engine-spring-7.8.0.jar!/:7.8.0]
	at org.camunda.bpm.engine.impl.interceptor.ProcessApplicationContextInterceptor.execute(ProcessApplicationContextInterceptor.java:66) ~[camunda-engine-7.8.0.jar!/:7.8.0]
	at org.camunda.bpm.engine.impl.interceptor.LogInterceptor.execute(LogInterceptor.java:30) ~[camunda-engine-7.8.0.jar!/:7.8.0]
	at org.camunda.bpm.engine.impl.jobexecutor.ExecuteJobHelper.executeJob(ExecuteJobHelper.java:36) [camunda-engine-7.8.0.jar!/:7.8.0]
	at org.camunda.bpm.engine.impl.jobexecutor.ExecuteJobHelper.executeJob(ExecuteJobHelper.java:29) [camunda-engine-7.8.0.jar!/:7.8.0]
	at org.camunda.bpm.engine.impl.jobexecutor.ExecuteJobsRunnable.executeJob(ExecuteJobsRunnable.java:88) [camunda-engine-7.8.0.jar!/:7.8.0]
	at org.camunda.bpm.engine.impl.jobexecutor.ExecuteJobsRunnable.run(ExecuteJobsRunnable.java:57) [camunda-engine-7.8.0.jar!/:7.8.0]
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [na:1.8.0_151]
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [na:1.8.0_151]
	at java.lang.Thread.run(Thread.java:748) [na:1.8.0_151]

2019-04-12 09:30:58.005  WARN 1 --- [ool-3-thread-11] org.camunda.bpm.engine.jobexecutor       : ENGINE-14006 Exception while executing job 286519c5-56e3-11e9-aad6-0a580a4d1372: 

java.lang.NullPointerException: null
	at org.camunda.bpm.engine.impl.jobexecutor.historycleanup.HistoryCleanupBatch.recordValue(HistoryCleanupBatch.java:88) ~[camunda-engine-7.8.0.jar!/:7.8.0]
	at org.camunda.bpm.engine.impl.jobexecutor.historycleanup.HistoryCleanupBatch.performCleanup(HistoryCleanupBatch.java:69) ~[camunda-engine-7.8.0.jar!/:7.8.0]
	at org.camunda.bpm.engine.impl.jobexecutor.historycleanup.HistoryCleanupJobHandler.execute(HistoryCleanupJobHandler.java:40) ~[camunda-engine-7.8.0.jar!/:7.8.0]
	at org.camunda.bpm.engine.impl.jobexecutor.historycleanup.HistoryCleanupJobHandler.execute(HistoryCleanupJobHandler.java:16) ~[camunda-engine-7.8.0.jar!/:7.8.0]
	at org.camunda.bpm.engine.impl.persistence.entity.JobEntity.execute(JobEntity.java:129) ~[camunda-engine-7.8.0.jar!/:7.8.0]
	at org.camunda.bpm.engine.impl.cmd.ExecuteJobsCmd.execute(ExecuteJobsCmd.java:99) ~[camunda-engine-7.8.0.jar!/:7.8.0]
	at org.camunda.bpm.engine.impl.cmd.ExecuteJobsCmd.execute(ExecuteJobsCmd.java:36) ~[camunda-engine-7.8.0.jar!/:7.8.0]
	at org.camunda.bpm.engine.impl.interceptor.CommandExecutorImpl.execute(CommandExecutorImpl.java:24) ~[camunda-engine-7.8.0.jar!/:7.8.0]
	at org.camunda.bpm.engine.impl.interceptor.CommandContextInterceptor.execute(CommandContextInterceptor.java:104) ~[camunda-engine-7.8.0.jar!/:7.8.0]
	at org.camunda.bpm.engine.spring.SpringTransactionInterceptor$1.doInTransaction(SpringTransactionInterceptor.java:42) ~[camunda-engine-spring-7.8.0.jar!/:7.8.0]
	at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:140) ~[spring-tx-5.0.6.RELEASE.jar!/:5.0.6.RELEASE]
	at org.camunda.bpm.engine.spring.SpringTransactionInterceptor.execute(SpringTransactionInterceptor.java:40) ~[camunda-engine-spring-7.8.0.jar!/:7.8.0]
	at org.camunda.bpm.engine.impl.interceptor.ProcessApplicationContextInterceptor.execute(ProcessApplicationContextInterceptor.java:66) ~[camunda-engine-7.8.0.jar!/:7.8.0]
	at org.camunda.bpm.engine.impl.interceptor.LogInterceptor.execute(LogInterceptor.java:30) ~[camunda-engine-7.8.0.jar!/:7.8.0]
	at org.camunda.bpm.engine.impl.jobexecutor.ExecuteJobHelper.executeJob(ExecuteJobHelper.java:36) ~[camunda-engine-7.8.0.jar!/:7.8.0]
	at org.camunda.bpm.engine.impl.jobexecutor.ExecuteJobHelper.executeJob(ExecuteJobHelper.java:29) ~[camunda-engine-7.8.0.jar!/:7.8.0]
	at org.camunda.bpm.engine.impl.jobexecutor.ExecuteJobsRunnable.executeJob(ExecuteJobsRunnable.java:88) ~[camunda-engine-7.8.0.jar!/:7.8.0]
	at org.camunda.bpm.engine.impl.jobexecutor.ExecuteJobsRunnable.run(ExecuteJobsRunnable.java:57) ~[camunda-engine-7.8.0.jar!/:7.8.0]
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [na:1.8.0_151]
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [na:1.8.0_151]
	at java.lang.Thread.run(Thread.java:748) [na:1.8.0_151]

Any idea why this is happening and how do I resolve it?

Hi @Rataum,

could you post your process engine configuration (either the configuration code or the configuration file) here?

From the Camunda BPM code from version 7.8.0 it rather looks like something is wrong in the engine setup here.

Cheers,
Tobias

Hi @tmetzke,

Here is my configuration:

	@Bean
	public SpringProcessEngineConfiguration processEngineConfiguration(
			@Qualifier("environment") Environment environment) throws SQLException, IOException {
		SpringProcessEngineConfiguration config = new SpringProcessEngineConfiguration();

		config.setDatabaseSchema("YL");
		config.setDatabaseTablePrefix("YL.");
		config.setDatabaseType("oracle");
		config.setDatabaseSchemaUpdate("false");
		config.setJdbcDriver(environment.getProperty("DATABASE_DRIVER"));
		config.setProcessEngineName("default");
		config.getProcessEnginePlugins().add(spinProcessEnginePlugin());
		config.setAuthorizationEnabled(true);
		config.setDataSource(dataSource(environment));
		config.setHistory("full");
		config.setJdbcBatchProcessing(false);
		config.setJdbcMaxActiveConnections(Integer.parseInt(environment.getProperty("POOL_CONNECTION")));
		config.setJdbcMaxIdleConnections(5);
		config.setJdbcMaxWaitTime(1000);
		config.setJdbcPingQuery("select 1 from dual");
		config.setJobExecutorActivate(true);
		config.setJobExecutorDeploymentAware(true);
		config.setMetricsEnabled(false);
		config.setTransactionManager(transactionManager(environment));
		config.setBatchOperationHistoryTimeToLive("P2D");

		// deploy all processes
		Resource[] resources = resourceLoader.getResources("classpath:/*.bpmn");
		config.setDeploymentResources(resources);
		config.setIdGenerator(new StrongUuidGenerator());

		return config;
	}

Hi @Rataum,

thanks!

Could you add

config.setHistoryCleanupMetricsEnabled(false);

to your configuration and try it again?
This should lead to the problematic line of code not being executed anymore.

Cheers,
Tobias

1 Like

Thanks @tmetzke!

Now it runs without errors, I will see if history has been cleaned.
One question: I use this code to see the finished history, will it show me if the history has been cleaned?

historyService.createHistoricProcessInstanceQuery().finished().count()

Hi @Rataum,

glad it works for you!

Yes, that should return 0 after the cleanup, assuming no other instance has finished in the meantime.

Cheers,
Tobias