From 695efac57879b676d7d6d92d83811558b2dc0d67 Mon Sep 17 00:00:00 2001
From: neil_a_wilson <neil_a_wilson@localhost>
Date: Thu, 02 Aug 2007 21:47:09 +0000
Subject: [PATCH] Fix a potential deadlock in the task code that could occur if a client tried to retrieve the task entry at the same time that it was being updated.
---
opends/src/server/org/opends/server/backends/task/Task.java | 56 ++++++++++++++++++++++++++++++++++++++++++++++++--------
1 files changed, 48 insertions(+), 8 deletions(-)
diff --git a/opends/src/server/org/opends/server/backends/task/Task.java b/opends/src/server/org/opends/server/backends/task/Task.java
index 39ae64d..8879aba 100644
--- a/opends/src/server/org/opends/server/backends/task/Task.java
+++ b/opends/src/server/org/opends/server/backends/task/Task.java
@@ -555,7 +555,14 @@
*/
void setTaskState(TaskState taskState)
{
- Lock lock = taskScheduler.writeLockEntry(taskEntryDN);
+ // We only need to grab the entry-level lock if we don't already hold the
+ // broader scheduler lock.
+ boolean needLock = (! taskScheduler.holdsSchedulerLock());
+ Lock lock = null;
+ if (needLock)
+ {
+ lock = taskScheduler.writeLockEntry(taskEntryDN);
+ }
try
{
@@ -579,7 +586,10 @@
}
finally
{
- taskScheduler.unlockEntry(taskEntryDN, lock);
+ if (needLock)
+ {
+ taskScheduler.unlockEntry(taskEntryDN, lock);
+ }
}
}
@@ -625,7 +635,14 @@
*/
private void setActualStartTime(long actualStartTime)
{
- Lock lock = taskScheduler.writeLockEntry(taskEntryDN);
+ // We only need to grab the entry-level lock if we don't already hold the
+ // broader scheduler lock.
+ boolean needLock = (! taskScheduler.holdsSchedulerLock());
+ Lock lock = null;
+ if (needLock)
+ {
+ lock = taskScheduler.writeLockEntry(taskEntryDN);
+ }
try
{
@@ -654,7 +671,10 @@
}
finally
{
- taskScheduler.unlockEntry(taskEntryDN, lock);
+ if (needLock)
+ {
+ taskScheduler.unlockEntry(taskEntryDN, lock);
+ }
}
}
@@ -685,7 +705,14 @@
*/
private void setCompletionTime(long completionTime)
{
- Lock lock = taskScheduler.writeLockEntry(taskEntryDN);
+ // We only need to grab the entry-level lock if we don't already hold the
+ // broader scheduler lock.
+ boolean needLock = (! taskScheduler.holdsSchedulerLock());
+ Lock lock = null;
+ if (needLock)
+ {
+ lock = taskScheduler.writeLockEntry(taskEntryDN);
+ }
try
{
@@ -714,7 +741,10 @@
}
finally
{
- taskScheduler.unlockEntry(taskEntryDN, lock);
+ if (needLock)
+ {
+ taskScheduler.unlockEntry(taskEntryDN, lock);
+ }
}
}
@@ -879,7 +909,14 @@
public void addLogMessage(ErrorLogSeverity severity, int messageID,
String messageString)
{
- Lock lock = taskScheduler.writeLockEntry(taskEntryDN);
+ // We only need to grab the entry-level lock if we don't already hold the
+ // broader scheduler lock.
+ boolean needLock = (! taskScheduler.holdsSchedulerLock());
+ Lock lock = null;
+ if (needLock)
+ {
+ lock = taskScheduler.writeLockEntry(taskEntryDN);
+ }
try
{
@@ -935,7 +972,10 @@
}
finally
{
- taskScheduler.unlockEntry(taskEntryDN, lock);
+ if (needLock)
+ {
+ taskScheduler.unlockEntry(taskEntryDN, lock);
+ }
}
}
--
Gitblit v1.10.0