forked from eclipse-ee4j/eclipselink
-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
HW-53073: Allow Thread Interruption for WriteLockManager #1
Open
agupta-hw
wants to merge
14
commits into
2.7
Choose a base branch
from
allow_thread_interrupt
base: 2.7
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 10 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
ad09e39
HW-53073: Allow Thread Interruption for WriteLockManager
agupta-hw e9e72ae
more logging.
agupta-hw fb013ff
more logging.
agupta-hw 2d68361
more logging.
agupta-hw ef37683
wait 1 min before interrupt.
agupta-hw fdb4970
wait 1 min before interrupt.
agupta-hw c4663eb
writelock stuff changes.
agupta-hw 965591d
log changes
agupta-hw 35bff2a
log changes
agupta-hw 4db2cb3
bump 70 to 130
agupta-hw 5cd96c3
renames.
agupta-hw d22ff4a
renames.
agupta-hw c6f50ef
new logic with flag based conditionals.
agupta-hw 5d35263
new logic with flag based conditionals.
agupta-hw File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
*.iml | ||
.idea/* | ||
.DS_Store | ||
*.class | ||
*test.jar | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,27 +22,26 @@ | |
// - 526957 : Split the logging and trace messages | ||
package org.eclipse.persistence.internal.helper; | ||
|
||
import java.util.IdentityHashMap; | ||
import java.util.Iterator; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import org.eclipse.persistence.descriptors.ClassDescriptor; | ||
import org.eclipse.persistence.descriptors.FetchGroupManager; | ||
import org.eclipse.persistence.exceptions.ConcurrencyException; | ||
import org.eclipse.persistence.internal.helper.linkedlist.ExposedNodeLinkedList; | ||
import org.eclipse.persistence.internal.identitymaps.CacheKey; | ||
import org.eclipse.persistence.internal.localization.LoggingLocalization; | ||
import org.eclipse.persistence.internal.localization.TraceLocalization; | ||
import org.eclipse.persistence.internal.queries.ContainerPolicy; | ||
import org.eclipse.persistence.internal.sessions.AbstractSession; | ||
import org.eclipse.persistence.internal.sessions.MergeManager; | ||
import org.eclipse.persistence.internal.sessions.ObjectChangeSet; | ||
import org.eclipse.persistence.internal.sessions.UnitOfWorkChangeSet; | ||
import org.eclipse.persistence.internal.sessions.UnitOfWorkImpl; | ||
import org.eclipse.persistence.internal.sessions.*; | ||
import org.eclipse.persistence.logging.SessionLog; | ||
import org.eclipse.persistence.mappings.DatabaseMapping; | ||
|
||
import java.time.LocalDateTime; | ||
import java.time.temporal.ChronoUnit; | ||
import java.util.IdentityHashMap; | ||
import java.util.Iterator; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.logging.Level; | ||
import java.util.logging.Logger; | ||
|
||
/** | ||
* INTERNAL: | ||
* <p> | ||
|
@@ -60,11 +59,17 @@ | |
* @since 10.0.3 | ||
*/ | ||
public class WriteLockManager { | ||
private static Logger logger = Logger.getLogger(WriteLockManager.class.getSimpleName()); | ||
|
||
// this will allow us to prevent a readlock thread from looping forever. | ||
public static final int MAXTRIES = 10000; | ||
|
||
public static final int MAX_WAIT = 600000; //10 mins | ||
private static final int SIXTY_SECONDS = 60; //1 minute | ||
private static final int SEVENTY_SECONDS = 130; //Once we reached 130s, we can assume we are in a bad state, so allow interruption for everything. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. comment isn't accurate. Should be |
||
//Initialize with 0 when we first find a lock. | ||
//is volatile enough for this case? How do we guarantee Thread-Safe access? Do we want to add more complexity with synchronized | ||
private static volatile LocalDateTime honourInterruptsWithin70secondsOfThisTime = LocalDateTime.now().minusYears(1); | ||
|
||
/* This attribute stores the list of threads that have had a problem acquiring locks */ | ||
/* the first element in this list will be the prevailing thread */ | ||
|
@@ -84,6 +89,7 @@ public Map acquireLocksForClone(Object objectForClone, ClassDescriptor descripto | |
IdentityHashMap lockedObjects = new IdentityHashMap(); | ||
IdentityHashMap refreshedObjects = new IdentityHashMap(); | ||
try { | ||
LocalDateTime localTime = null; | ||
// if the descriptor has indirection for all mappings then wait as there will be no deadlock risks | ||
CacheKey toWaitOn = acquireLockAndRelatedLocks(objectForClone, lockedObjects, refreshedObjects, cacheKey, descriptor, cloningSession); | ||
int tries = 0; | ||
|
@@ -98,7 +104,34 @@ public Map acquireLocksForClone(Object objectForClone, ClassDescriptor descripto | |
toWaitOn.wait();// wait for lock on object to be released | ||
} | ||
} catch (InterruptedException ex) { | ||
// Ignore exception thread should continue. | ||
//https://jira.site1.hyperwallet.local/browse/HW-53073 | ||
//Custom change to allow thread interruptions for bad threads stuck in org.eclipse.persistence.internal.helper.WriteLockManager.acquireLocksForClone pattern | ||
jportner-hw marked this conversation as resolved.
Show resolved
Hide resolved
|
||
long secondsPassed = ChronoUnit.SECONDS.between(honourInterruptsWithin70secondsOfThisTime, LocalDateTime.now()); | ||
if (secondsPassed < SEVENTY_SECONDS) { | ||
logger.log(Level.SEVERE, | ||
"Static Timer: Reached threshold to interrupt. Attempts: {0}, Time elapsed in seconds: {1}, Timer: {2}", | ||
new Object[]{tries, | ||
secondsPassed, honourInterruptsWithin70secondsOfThisTime}); | ||
throw ConcurrencyException.waitWasInterrupted(ex.getMessage()); | ||
} else { | ||
agupta-hw marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (localTime == null) { | ||
localTime = LocalDateTime.now(); | ||
} | ||
long secondsPassedLocally = ChronoUnit.SECONDS.between(localTime, LocalDateTime.now()); | ||
if (secondsPassedLocally < SIXTY_SECONDS) { | ||
logger.log(Level.WARNING, | ||
"This is a custom eclipselink change to allow interrupts, it will not interrupt till 1 minute. Attempts: " | ||
+ "{0}, Time elapsed in seconds: {1}, Local Timer: {2}, Static Timer: {3}", | ||
new Object[]{tries, secondsPassedLocally, localTime, honourInterruptsWithin70secondsOfThisTime}); | ||
} else { | ||
logger.log(Level.SEVERE, | ||
"Local Timer: Reached threshold to interrupt. Attempts: {0}, Time elapsed in seconds: {1}, Local Timer: " | ||
+ "{2}, Static Timer: {3}", | ||
new Object[]{tries, secondsPassed, localTime, honourInterruptsWithin70secondsOfThisTime}); | ||
honourInterruptsWithin70secondsOfThisTime = LocalDateTime.now(); | ||
throw ConcurrencyException.waitWasInterrupted(ex.getMessage()); | ||
} | ||
} | ||
} | ||
} | ||
Object waitObject = toWaitOn.getObject(); | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Constant should be named for their purpose, not their value.
SIXTY_SECONDS should be SECONDS_BEFORE_HONOUR_INTERRUPT
SEVENTY_SECONDS should be SECONDS_IN_BAD_STATE