# deleteSequentiallyUsingBatch not working with HistoricProcessInstanceQuery after upgrading flowable version

**URL:** <https://forum.flowable.org/t/deletesequentiallyusingbatch-not-working-with-historicprocessinstancequery-after-upgrading-flowable-version/10751>\
**Category:** Flowable Engine\
**Created:** [August 8, 2023, 3:59pm UTC](https://forum.flowable.org/t/deletesequentiallyusingbatch-not-working-with-historicprocessinstancequery-after-upgrading-flowable-version/10751 "2023-08-08T15:59:16Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![renuka\_s](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/renuka_s/32/3242_2.png) [@renuka\_s](https://forum.flowable.org/u/renuka_s)\
**Post date:** [August 8, 2023, 3:59pm UTC](https://forum.flowable.org/t/deletesequentiallyusingbatch-not-working-with-historicprocessinstancequery-after-upgrading-flowable-version/10751/1 "2023-08-08T15:59:16Z")

</div>

I have upgraded my flowable version to 6.8.0 from 6.6.0. I am trying to write a script that would delete historic data.  
I have created HistoricProcessInstanceQuery as -

```auto
HistoricProcessInstanceQuery query = processEngineConfiguration.getHistoryService()
                    .createHistoricProcessInstanceQuery()
                    .startedBefore(date);
query.deleteSequentiallyUsingBatch(2, "historic-data-deletion")

```

But this is not working. HistoricProcessInstanceQuery is successfully getting created and I am getting intended data as well but `deleteSequentiallyUsingBatch` function is not working. Although `query.deleteWithRelatedData()` is working perfectly fine.

I have upgraded the flowable version but not the DB version. Can somebody please help me with this?  
Also i would like to mention while upgrading flowable from 6.6.0 to 6.8.0 the flowable properties that are set in my spring boot application is-

```auto
flowable.idm.enabled=false
flowable.database-schema-update=false
flowable.check-process-definitions=true

```

Please help me with this issue

Further debugging the issue, and checking the sql history I see that few insert queries are getting triggered internally and delete query is never triggered.

```auto
select count(distinct RES.ID_)
       
    from ACT_HI_PROCINST RES
    
    left outer join ACT_RE_PROCDEF DEF on RES.PROC_DEF_ID_ = DEF.ID_
     
     WHERE RES.START_TIME_ <= '2023-07-12 00:00:00';

insert into ACT_GE_BYTEARRAY(ID_, REV_, NAME_, BYTES_, DEPLOYMENT_ID_)
    values (
      'd6f9a5a1-3681-11ee-a880-aaaf421bc944',
      1, 
      'batchDocumentJson', 
      _binary'{"numberOfInstances":1,"batchSize":1,"sequential":true,"query":{"startedBefore":"2023-07-11T18:30:00.000Z"}}', 
      null
    );
    
insert into ACT_RU_JOB (
        ID_,
        REV_,
        CATEGORY_,
        TYPE_,
        LOCK_OWNER_,
        LOCK_EXP_TIME_,
        EXCLUSIVE_,
        EXECUTION_ID_,
        PROCESS_INSTANCE_ID_,
        PROC_DEF_ID_,
        ELEMENT_ID_,
        ELEMENT_NAME_,
        SCOPE_ID_, 
        SUB_SCOPE_ID_, 
        SCOPE_TYPE_, 
        SCOPE_DEFINITION_ID_,
        CORRELATION_ID_,
        RETRIES_,
        EXCEPTION_STACK_ID_,
        EXCEPTION_MSG_,
        DUEDATE_,
        REPEAT_,
        HANDLER_TYPE_,
        HANDLER_CFG_,
        CUSTOM_VALUES_ID_,
        CREATE_TIME_,
        TENANT_ID_)
        values ('d6f9ccb5-3681-11ee-a880-aaaf421bc944',
        1,
        null,
        'message',
        null,
        null,
        0,
        null,
        null,
        null,
        null,
        null,
        null,
        null,
        null,
        null,
        'd6f9ccb4-3681-11ee-a880-aaaf421bc944',
        3,
        null,
        null,
        null,
        null,
        'delete-historic-processes-sequential',
        'd6f9a5a3-3681-11ee-a880-aaaf421bc944',
        null,
        '2023-08-09 12:26:18.044',
        ''
        )
        
INSERT INTO FLW_RU_BATCH(ID_, REV_, TYPE_, SEARCH_KEY_, SEARCH_KEY2_, CREATE_TIME_, COMPLETE_TIME_, STATUS_, BATCH_DOC_ID_, TENANT_ID_)
        VALUES ('d6f9a5a2-3681-11ee-a880-aaaf421bc944',
                1,
                'historicProcessDelete',
                'historic-data-deletion',
                null,
                '2023-08-09 12:26:18.043',
                null,
                'inProgress',
                'd6f9a5a1-3681-11ee-a880-aaaf421bc944',
                null)
                
INSERT INTO FLW_RU_BATCH_PART(ID_, REV_, BATCH_ID_, TYPE_, SCOPE_ID_, SUB_SCOPE_ID_, SCOPE_TYPE_, SEARCH_KEY_, SEARCH_KEY2_, STATUS_, CREATE_TIME_, COMPLETE_TIME_, RESULT_DOC_ID_, TENANT_ID_)
        VALUES ('d6f9a5a3-3681-11ee-a880-aaaf421bc944',
            1,
            'd6f9a5a2-3681-11ee-a880-aaaf421bc944',
            'deleteProcess',
            null,
            null,
            null,
            '0',
            null,
            'waiting',
            '2023-08-09 12:26:18.043',
            null,
            null,
            null)

```

My guess is internally only half of the queries are getting triggered. Any suggestions on why that might be happening?

---

<div class="post-metadata">

**Author:** ![MirekSz](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/mireksz/32/2112_2.png) [@MirekSz](https://forum.flowable.org/u/MirekSz)\
**Post date:** [August 24, 2023, 1:18pm UTC](https://forum.flowable.org/t/deletesequentiallyusingbatch-not-working-with-historicprocessinstancequery-after-upgrading-flowable-version/10751/2 "2023-08-24T13:18:39Z")

</div>

We are deleting in following way

```auto
	HistoricProcessInstanceQuery query = Flowable.getConfig().getHistoryCleaningManager().createHistoricProcessInstanceCleaningQuery();
		query.finishedBefore(date);
		query.deleteSequentiallyUsingBatch(BATCH_SIZE, BATCH_NAME);

```

---

<div class="post-metadata">

**Author:** ![renuka\_s](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/renuka_s/32/3242_2.png) [@renuka\_s](https://forum.flowable.org/u/renuka_s)\
**Post date:** [August 29, 2023, 8:33am UTC](https://forum.flowable.org/t/deletesequentiallyusingbatch-not-working-with-historicprocessinstancequery-after-upgrading-flowable-version/10751/3 "2023-08-29T08:33:42Z")

</div>

@MirekSz you are using version 6.8.0 right? Also I am not getting function getConfig from Flowable class. What can be the reason for this? Do you think it can be any issue related to the way flowable is configured for us?

 ![Screenshot 2023-08-29 at 2.14.23 PM](https://canada1.discourse-cdn.com/flex035/uploads/flowable/original/2X/2/286cb4e47b5f169544f1baa4c3165d17ec899006.png)

---

<div class="post-metadata">

**Author:** ![MirekSz](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/mireksz/32/2112_2.png) [@MirekSz](https://forum.flowable.org/u/MirekSz)\
**Post date:** [August 29, 2023, 9:32am UTC](https://forum.flowable.org/t/deletesequentiallyusingbatch-not-working-with-historicprocessinstancequery-after-upgrading-flowable-version/10751/4 "2023-08-29T09:32:14Z")

</div>

I’m using 6.8.0, Flowable.getConfig() is our wrapper for StandaloneProcessEngineConfiguration

And we have following configuraion

```auto
			cfg.setAsyncExecutorActivate(true);
			cfg.setAsyncExecutorMaxPoolSize(16);
			cfg.setAsyncExecutorCorePoolSize(16);
			cfg.setAsyncHistoryExecutorCorePoolSize(16);
			cfg.setAsyncHistoryExecutorMaxPoolSize(16);

```

After execution of `deleteSequentiallyUsingBatch` do you see any records in tables flw\_ru\_batch/flw\_ru\_batch\_part?

---

<div class="post-metadata">

**Author:** ![renuka\_s](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/renuka_s/32/3242_2.png) [@renuka\_s](https://forum.flowable.org/u/renuka_s)\
**Post date:** [August 29, 2023, 12:05pm UTC](https://forum.flowable.org/t/deletesequentiallyusingbatch-not-working-with-historicprocessinstancequery-after-upgrading-flowable-version/10751/5 "2023-08-29T12:05:48Z")

</div>

Yes I see the data both in flw\_ru\_batch/flw\_ru\_batch\_part tables. I am attaching the entries as well. But it did not delete the process instance

 ![Screenshot 2023-08-29 at 5.32.21 PM](https://canada1.discourse-cdn.com/flex035/uploads/flowable/original/2X/4/478ba0d43942e3a0cdd11e10b80cd67e0b672656.png)  
 ![Screenshot 2023-08-29 at 5.32.44 PM](https://canada1.discourse-cdn.com/flex035/uploads/flowable/original/2X/0/0d890297832c527c1cec47bebf1f53c3a9e13234.png)

It do contain the data bit I see the status is **InProgress** and **waiting** in **flw\_ru\_batch** and **flw\_ru\_batch\_part** tables respectively. That’s where I am confused that why is it happening. In my detailed description as well I have mentioned that half of the queries are getting executed. @MirekSz also can you help me with your code snippet for wrapper for StandaloneProcessEngineConfiguration. Not sure if that is the problem but can try it once

---

<div class="post-metadata">

**Author:** ![MirekSz](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/mireksz/32/2112_2.png) [@MirekSz](https://forum.flowable.org/u/MirekSz)\
**Post date:** [August 29, 2023, 1:19pm UTC](https://forum.flowable.org/t/deletesequentiallyusingbatch-not-working-with-historicprocessinstancequery-after-upgrading-flowable-version/10751/6 "2023-08-29T13:19:04Z")

</div>

You should wait until records in above tables get status “completed”

`StandaloneProcessEngineConfiguration cfg = new StandaloneProcessEngineConfiguration()

```auto
cfg.setAsyncExecutorActivate(true);
cfg.setAsyncExecutorMaxPoolSize(16);
cfg.setAsyncExecutorCorePoolSize(16);
cfg.setAsyncHistoryExecutorCorePoolSize(16);
cfg.setAsyncHistoryExecutorMaxPoolSize(16);

```

`

---

<div class="post-metadata">

**Author:** ![renuka\_s](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/renuka_s/32/3242_2.png) [@renuka\_s](https://forum.flowable.org/u/renuka_s)\
**Post date:** [August 30, 2023, 5:22am UTC](https://forum.flowable.org/t/deletesequentiallyusingbatch-not-working-with-historicprocessinstancequery-after-upgrading-flowable-version/10751/7 "2023-08-30T05:22:31Z")

</div>

@MirekSz I am not doing anything with the **flw\_ru\_batch** and **flw\_ru\_batch\_part** tables records. For example I executed the method yesterday and records got created. But till today the records status is InProgress only. Also on the application console i see warnings like-

```auto
2023-08-30 10:10:41.021 WARN (HikariPool-1 housekeeper) [com.zaxxer.hikari.pool.HikariPool] HikariPool-1 - Thread starvation or clock leap detected (housekeeper delta=5m12s869ms).
2023-08-30 10:10:48.307 WARN (HikariPool-2 housekeeper) [com.zaxxer.hikari.pool.HikariPool] HikariPool-2 - Thread starvation or clock leap detected (housekeeper delta=5m12s870ms).

```

Also how long do we need to wait in order to see whether the job would complete or not. It’s already 17 hours till the time records got inserted.
