TSK-1757: Added lock for update to custom attribute initialization.

This commit is contained in:
holgerhagen 2021-11-03 15:39:43 +01:00 committed by holgerhagen
parent 1df190d1da
commit e05120cc93
4 changed files with 16 additions and 5 deletions

View File

@ -8,6 +8,10 @@ import pro.taskana.common.api.exceptions.SystemException;
public class ParallelThreadHelper {
private ParallelThreadHelper() {
throw new IllegalStateException("Utility class");
}
public static void runInThread(Runnable runnable, int threadCount) throws Exception {
Thread[] threads = new Thread[threadCount];

View File

@ -14,8 +14,14 @@ public interface ConfigurationMapper {
@Insert("INSERT INTO CONFIGURATION(ENFORCE_SECURITY) VALUES (#{securityEnabled})")
void setSecurityEnabled(@Param("securityEnabled") boolean securityEnabled);
@Select("SELECT CUSTOM_ATTRIBUTES FROM CONFIGURATION")
Map<String, Object> getAllCustomAttributes();
@Select(
"<script> SELECT CUSTOM_ATTRIBUTES FROM CONFIGURATION "
+ "<if test='lockForUpdate == true'>"
+ "FETCH FIRST ROW ONLY FOR UPDATE "
+ "<if test=\"_databaseId == 'db2'\">WITH RS USE AND KEEP UPDATE LOCKS </if> "
+ "</if>"
+ "</script>")
Map<String, Object> getAllCustomAttributes(boolean lockForUpdate);
@Update("UPDATE CONFIGURATION SET CUSTOM_ATTRIBUTES = #{customAttributes}")
void setAllCustomAttributes(@Param("customAttributes") Map<String, ?> customAttributes);

View File

@ -47,7 +47,7 @@ public class ConfigurationServiceImpl implements ConfigurationService {
internalTaskanaEngine.executeInDatabaseConnection(
CheckedRunnable.wrap(
() -> {
if (mapper.getAllCustomAttributes() == null) {
if (mapper.getAllCustomAttributes(true) == null) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("custom attributes are not set. Setting default value");
}
@ -58,7 +58,8 @@ public class ConfigurationServiceImpl implements ConfigurationService {
@Override
public Map<String, Object> getAllCustomAttributes() {
return internalTaskanaEngine.executeInDatabaseConnection(mapper::getAllCustomAttributes);
return internalTaskanaEngine.executeInDatabaseConnection(
() -> mapper.getAllCustomAttributes(false));
}
@Override

View File

@ -41,7 +41,7 @@ public class ConfigurationServiceImplAccTest {
ConfigurationServiceImpl.class, "defaultCustomAttributes.json"))
.toMap();
Map<String, Object> allCustomAttributes = configurationMapper.getAllCustomAttributes();
Map<String, Object> allCustomAttributes = configurationMapper.getAllCustomAttributes(false);
assertThat(allCustomAttributes).isEqualTo(expectedCustomAttributes);
}