Sometimes INSERT MeterLogEntity Error when using runtimeService and taskService

Platform: Grails Plugin
Version: 7.5.0

Sometimes when executing runtimeService.setVariables, taskService.setVariables and taskService.complete will cause below error. Any advice will be appreciated.

ENGINE-03004 Exception while executing Database Operation 'INSERT MeterLogEntity[55901]' with message '
### Error updating database.  Cause: org.postgresql.util.PSQLException: Error: duplicate key constrain violataion "act_ru_meter_log_pkey"
  detail: key value "(id_)=(55901)" exists
### The error may involve org.camunda.bpm.engine.impl.persistence.entity.MeterLogEntity.insertMeterLog-Inline
### The error occurred while setting parameters
### SQL: insert into ACT_RU_METER_LOG (ID_, NAME_, REPORTER_, VALUE_, TIMESTAMP_)     values (       ?,       ?,       ?,       ?,       ?     )
### Cause: org.postgresql.util.PSQLException: Error: duplicate key constrain violataion "act_ru_meter_log_pkey"
  detail: key value "(id_)=(55901)" exists'. Flush summary: 
 [
  INSERT MeterLogEntity[55901]
  INSERT MeterLogEntity[55902]
  INSERT MeterLogEntity[55903]
  INSERT MeterLogEntity[55904]
  INSERT MeterLogEntity[55905]
  INSERT MeterLogEntity[55906]
  INSERT MeterLogEntity[55907]
  INSERT MeterLogEntity[55908]
  INSERT MeterLogEntity[55909]
]

Is there a specific reason you are using the deprecated DbIdGenerator as the engine’s id generator? If not, I recommend using StrongUuidGenerator.

Cheers,
Thorben

Hi Thorben,
I am NOT using DbIdGenerator. I am using the RuntimeSerive and TaskService. The error message is generated by the camunda engine.

I am just curious what would cause such error when dealing with workflow engine by using below classes.

  1. repositoryService
  2. runtimeService
  3. taskService
  4. formService
  5. historyService

Hi @GhostFox,

How do you configure the engine? The id generator is a configuration property of the process engine (i.e. you don’t use it directly) and the IDs of the entities you listed suggest that the deprecated class DbIdGenerator is in use.

Cheers,
Thorben

I am using the camunda plugin for Grails 2.5. This is all I have.

This is part of the code in my BuildConfig.groovy.

dependencies {
    compile ("org.camunda.bpm:camunda-engine:7.5.0") {
        excludes "spring-beans"
    }
    
    runtime ("org.camunda.bpm:camunda-engine-spring:7.5.0") {
        excludes "spring-context", "spring-jdbc", "spring-orm"
    }
}

plugins {
    compile "org.grails.plugins:camunda:0.5.0"
}

This is part of the code in my applicationContext.xml (Generated by plugin, data source connection configured by myself).

<bean id="dataSource" class="org.springframework.jdbc.datasource.TransactionAwareDataSourceProxy">
    <property name="targetDataSource">
        <bean class="org.springframework.jdbc.datasource.SimpleDriverDataSource">
            <property name="driverClass" value="org.postgresql.Driver" />
            <property name="url"
                      value="jdbc:postgresql://127.0.0.1:5432/camunda?autoreconnect=true&amp;useSSL=false&amp;useUnicode=true&amp;characterEncoding=UTF-8" />
            <property name="username" value="xxx" />
            <property name="password" value="xxx" />
        </bean>
    </property>
</bean>

<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
    <property name="dataSource" ref="dataSource" />
</bean>

<bean id="processEngineConfiguration" class="org.camunda.bpm.engine.spring.SpringProcessEngineConfiguration">
    <property name="processEngineName" value="engine" />
    <property name="dataSource" ref="dataSource" />
    <property name="transactionManager" ref="transactionManager" />
    <property name="databaseSchemaUpdate" value="true" />
    <property name="jobExecutorActivate" value="false" />
</bean>

<bean id="processEngine" class="org.camunda.bpm.engine.spring.ProcessEngineFactoryBean">
    <property name="processEngineConfiguration" ref="processEngineConfiguration" />
</bean>

<bean id="repositoryService" factory-bean="processEngine" factory-method="getRepositoryService" />
<bean id="runtimeService" factory-bean="processEngine" factory-method="getRuntimeService" />
<bean id="taskService" factory-bean="processEngine" factory-method="getTaskService" />
<bean id="historyService" factory-bean="processEngine" factory-method="getHistoryService" />
<bean id="managementService" factory-bean="processEngine" factory-method="getManagementService" />

Can anyone help on this, please?

More Details

  1. Any workflow engine interaction and ourselve system logic code execution.
  2. No error occurs right after execution.
  3. Maybe, 30 - 60 minutes after the execution, the error comes up in the console.
  4. Even the error comes up, NO side effect we’ve found in the process or our biz logic processing. Just like nothing happened except those error messages in the console.
  5. By tracking the error detail, this would caused by the class called org.camunda.bpm.engine.impl.metrics.reporter.MetricsCollectionTask
  6. The error occured while inserting data into ACT_RU_METER_LOG.

Finally, I found the root cause.

One of our developer used backup from another database server and restored the camunda database to his local. That caused this MetricsCollectionTask issue.

I identified this by query the data from ACT_RU_METER_LOG and found the REPORTER value contains different IP address.

SELECT * FROM ACT_RU_METER_LOG WHERE id_ IN ('57400', '57391', '57495', '57504', '57609', '57513')

After clearing his local ACT_RU_METER_LOG table, the error has gone.