Embedded process engine in a cluster with shared database

Hi,

I have a homogeneous cluster set up (multiple docker containers with spring boot embedded process engines all sharing the same database). All these containers start up around the same time. Since they start up around the same time, I get exceptions intermittently like

ENGINE-08043 Exception while performing ‘Deployment of Process Application camundaDataSourceConfig’ => 'Deployment of process archive ‘XXXX’: Process engine persistence exception
Caused by: org.apache.ibatis.exceptions.TooManyResultsException: Expected one result (or null) to be returned by selectOne(), but found: 2

When i debugged further I see that the stack trace is as follows:

Caused by: org.apache.ibatis.exceptions.TooManyResultsException: Expected one result (or null) to be returned by selectOne(), but found: 2
at org.apache.ibatis.session.defaults.DefaultSqlSession.selectOne(DefaultSqlSession.java:80) ~[mybatis-3.5.3.jar:3.5.3]
at org.camunda.bpm.engine.impl.db.sql.DbSqlSession.selectOne(DbSqlSession.java:117) ~[camunda-engine-7.13.0.jar:7.13.0]
at org.camunda.bpm.engine.impl.db.entitymanager.DbEntityManager.selectOne(DbEntityManager.java:186) ~[camunda-engine-7.13.0.jar:7.13.0]
at org.camunda.bpm.engine.impl.dmn.entity.repository.DecisionDefinitionManager.findLatestDecisionDefinitionByKeyAndTenantId(DecisionDefinitionManager.java:84) ~[camunda-engine-7.13.0.jar:7.13.0]
at org.camunda.bpm.engine.impl.dmn.deployer.DecisionDefinitionDeployer.findLatestDefinitionByKeyAndTenantId(DecisionDefinitionDeployer.java:106) ~[camunda-engine-7.13.0.jar:7.13.0]
at org.camunda.bpm.engine.impl.dmn.deployer.DecisionDefinitionDeployer.findLatestDefinitionByKeyAndTenantId(DecisionDefinitionDeployer.java:43) ~[camunda-engine-7.13.0.jar:7.13.0]

I assume that this is because all the containers contain the same version of DMN files and if two containers are started at the same time, both will update the version and insert a new row at the same time in ACT_RE_DECISION_DEF table. And since there are no tenant identifiers specified, it executes the below given query and returns two rows instead of the expected single row. How can I fix this with my current set up? Do I need to supply a tenant id? Or is there any other way to prevent such exceptions from occurring in the future?

select *
from ACT_RE_DECISION_DEF
where KEY_ = ‘MyDecision’
and TENANT_ID_ is null
and VERSION_ = (
select max(VERSION_)
from ACT_RE_DECISION_DEF
where KEY_ = ‘MyDecision’ and TENANT_ID_ is null)

you need to set the tenant id. Refer the existing thread.

But, how do i specify tenant id for each embedded engine? I mean we have a common process.xml for all the 4 embedded engines since it’s the same springboot jar that gets deployed to all containers