Skip to content

Commit 34c060e

Browse files
author
Jörg Heffner
committed
Closes Taskana#2374: Deadlock when creating HistoryEvents from many connections simultaneously
-Write operations are now performed with the regular TaskanEngine and its' SqlSession and TransactionFactory which provides the needed transactionality and doesn't open multiple connections
1 parent 31100a5 commit 34c060e

File tree

18 files changed

+262
-534
lines changed

18 files changed

+262
-534
lines changed

history/taskana-simplehistory-provider/src/main/java/pro/taskana/simplehistory/TaskanaHistoryEngine.java

Lines changed: 0 additions & 31 deletions
This file was deleted.

history/taskana-simplehistory-provider/src/main/java/pro/taskana/simplehistory/impl/ClassificationHistoryQueryImpl.java

Lines changed: 20 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import static pro.taskana.common.api.BaseQuery.toLowerCopy;
44

5-
import java.sql.SQLException;
65
import java.util.ArrayList;
76
import java.util.List;
87
import org.apache.ibatis.session.RowBounds;
@@ -12,6 +11,7 @@
1211
import pro.taskana.common.api.TimeInterval;
1312
import pro.taskana.common.api.exceptions.InvalidArgumentException;
1413
import pro.taskana.common.api.exceptions.SystemException;
14+
import pro.taskana.common.internal.InternalTaskanaEngine;
1515
import pro.taskana.simplehistory.impl.classification.ClassificationHistoryQuery;
1616
import pro.taskana.simplehistory.impl.classification.ClassificationHistoryQueryColumnName;
1717
import pro.taskana.spi.history.api.events.classification.ClassificationHistoryEvent;
@@ -33,7 +33,7 @@ public class ClassificationHistoryQueryImpl implements ClassificationHistoryQuer
3333
private static final String SQL_EXCEPTION_MESSAGE =
3434
"Method openConnection() could not open a connection to the database.";
3535

36-
private final TaskanaHistoryEngineImpl taskanaHistoryEngine;
36+
private final InternalTaskanaEngine internalTaskanaEngine;
3737

3838
private final List<String> orderBy = new ArrayList<>();
3939
private final List<String> orderColumns = new ArrayList<>();
@@ -82,8 +82,8 @@ public class ClassificationHistoryQueryImpl implements ClassificationHistoryQuer
8282
private String[] custom7Like;
8383
private String[] custom8Like;
8484

85-
public ClassificationHistoryQueryImpl(TaskanaHistoryEngineImpl internalTaskanaHistoryEngine) {
86-
this.taskanaHistoryEngine = internalTaskanaHistoryEngine;
85+
public ClassificationHistoryQueryImpl(InternalTaskanaEngine internalTaskanaEngine) {
86+
this.internalTaskanaEngine = internalTaskanaEngine;
8787
}
8888

8989
@Override
@@ -415,32 +415,26 @@ public ClassificationHistoryQuery orderByCustomAttribute(int num, SortDirection
415415

416416
@Override
417417
public List<ClassificationHistoryEvent> list() {
418-
List<ClassificationHistoryEvent> result = new ArrayList<>();
418+
List<ClassificationHistoryEvent> result;
419419
try {
420-
taskanaHistoryEngine.openConnection();
421-
result = taskanaHistoryEngine.getSqlSession().selectList(LINK_TO_MAPPER, this);
422-
return result;
423-
} catch (SQLException e) {
424-
LOGGER.error(SQL_EXCEPTION_MESSAGE, e.getCause());
420+
internalTaskanaEngine.openConnection();
421+
result = internalTaskanaEngine.getSqlSession().selectList(LINK_TO_MAPPER, this);
425422
return result;
426423
} finally {
427-
taskanaHistoryEngine.returnConnection();
424+
internalTaskanaEngine.returnConnection();
428425
}
429426
}
430427

431428
@Override
432429
public List<ClassificationHistoryEvent> list(int offset, int limit) {
433430
List<ClassificationHistoryEvent> result = new ArrayList<>();
434431
try {
435-
taskanaHistoryEngine.openConnection();
432+
internalTaskanaEngine.openConnection();
436433
RowBounds rowBounds = new RowBounds(offset, limit);
437-
result = taskanaHistoryEngine.getSqlSession().selectList(LINK_TO_MAPPER, this, rowBounds);
438-
return result;
439-
} catch (SQLException e) {
440-
LOGGER.error(SQL_EXCEPTION_MESSAGE, e.getCause());
434+
result = internalTaskanaEngine.getSqlSession().selectList(LINK_TO_MAPPER, this, rowBounds);
441435
return result;
442436
} finally {
443-
taskanaHistoryEngine.returnConnection();
437+
internalTaskanaEngine.returnConnection();
444438
}
445439
}
446440

@@ -454,17 +448,14 @@ public List<String> listValues(
454448
this.addOrderCriteria(columnName.toString(), sortDirection);
455449

456450
try {
457-
taskanaHistoryEngine.openConnection();
458-
result = taskanaHistoryEngine.getSqlSession().selectList(LINK_TO_VALUE_MAPPER, this);
459-
return result;
460-
} catch (SQLException e) {
461-
LOGGER.error(SQL_EXCEPTION_MESSAGE, e.getCause());
451+
internalTaskanaEngine.openConnection();
452+
result = internalTaskanaEngine.getSqlSession().selectList(LINK_TO_VALUE_MAPPER, this);
462453
return result;
463454
} finally {
464455
this.orderBy.addAll(cacheOrderBy);
465456
this.columnName = null;
466457
this.orderColumns.remove(orderColumns.size() - 1);
467-
taskanaHistoryEngine.returnConnection();
458+
internalTaskanaEngine.returnConnection();
468459
}
469460
}
470461

@@ -473,30 +464,24 @@ public ClassificationHistoryEvent single() {
473464
ClassificationHistoryEvent result = null;
474465
try {
475466

476-
taskanaHistoryEngine.openConnection();
477-
result = taskanaHistoryEngine.getSqlSession().selectOne(LINK_TO_MAPPER, this);
467+
internalTaskanaEngine.openConnection();
468+
result = internalTaskanaEngine.getSqlSession().selectOne(LINK_TO_MAPPER, this);
478469

479-
return result;
480-
} catch (SQLException e) {
481-
LOGGER.error(SQL_EXCEPTION_MESSAGE, e.getCause());
482470
return result;
483471
} finally {
484-
taskanaHistoryEngine.returnConnection();
472+
internalTaskanaEngine.returnConnection();
485473
}
486474
}
487475

488476
@Override
489477
public long count() {
490478
Long rowCount = null;
491479
try {
492-
taskanaHistoryEngine.openConnection();
493-
rowCount = taskanaHistoryEngine.getSqlSession().selectOne(LINK_TO_COUNTER, this);
480+
internalTaskanaEngine.openConnection();
481+
rowCount = internalTaskanaEngine.getSqlSession().selectOne(LINK_TO_COUNTER, this);
494482
return (rowCount == null) ? 0L : rowCount;
495-
} catch (SQLException e) {
496-
LOGGER.error(SQL_EXCEPTION_MESSAGE, e.getCause());
497-
return -1;
498483
} finally {
499-
taskanaHistoryEngine.returnConnection();
484+
internalTaskanaEngine.returnConnection();
500485
}
501486
}
502487

0 commit comments

Comments
 (0)