Github user chtyim commented on a diff in the pull request:
https://github.com/apache/incubator-tephra/pull/23#discussion_r91470597
--- Diff:
tephra-core/src/main/java/org/apache/tephra/TransactionManager.java ---
@@ -340,48 +340,51 @@ public long getSleepMillis() {
private void cleanupTimedOutTransactions() {
List<TransactionEdit> invalidEdits = null;
- this.logReadLock.lock();
- try {
- synchronized (this) {
- if (!isRunning()) {
- return;
- }
+ synchronized (this) {
+ if (!isRunning()) {
+ return;
+ }
- long currentTime = System.currentTimeMillis();
- List<Long> timedOut = Lists.newArrayList();
- for (Map.Entry<Long, InProgressTx> tx : inProgress.entrySet()) {
- long expiration = tx.getValue().getExpiration();
- if (expiration >= 0L && currentTime > expiration) {
- // timed out, remember tx id (can't remove while iterating
over entries)
- timedOut.add(tx.getKey());
- LOG.info("Tx invalid list: added tx {} because of timeout",
tx.getKey());
- } else if (expiration < 0) {
- LOG.warn("Transaction {} has negative expiration time {}.
Likely cause is the transaction was not " +
- "migrated correctly, this transaction will be
expired immediately",
- tx.getKey(), expiration);
- timedOut.add(tx.getKey());
- }
+ long currentTime = System.currentTimeMillis();
+ Map<Long, InProgressType> timedOut = Maps.newHashMap();
+ for (Map.Entry<Long, InProgressTx> tx : inProgress.entrySet()) {
+ long expiration = tx.getValue().getExpiration();
+ if (expiration >= 0L && currentTime > expiration) {
+ // timed out, remember tx id (can't remove while iterating over
entries)
+ timedOut.put(tx.getKey(), tx.getValue().getType());
+ LOG.info("Tx invalid list: added tx {} because of timeout",
tx.getKey());
+ } else if (expiration < 0) {
+ LOG.warn("Transaction {} has negative expiration time {}. Likely
cause is the transaction was not " +
+ "migrated correctly, this transaction will be expired
immediately",
+ tx.getKey(), expiration);
+ timedOut.put(tx.getKey(), InProgressType.LONG);
}
- if (!timedOut.isEmpty()) {
+ }
+ if (!timedOut.isEmpty()) {
+ logWriteLock.lock();
--- End diff --
Looking at the code again, my understand of the lock in this method is
wrong. The whole method itself is synchronized on `this` object (with
`synchronize(this)` covering almost the entire method). The `logReadLock` is
for locking on the transaction log writer, which apparently it only needs the
read lock in order to call `appendToLog`. It's probably safer to revert to old
way of locking first. Need further study on the locking mechanism on this class
(apparently there are three locks, one on `this` logic, one read and one write
lock on the tx log).
Sorry for my previous comment.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---