Author: jflesch
Date: 2006-07-19 19:32:52 +0000 (Wed, 19 Jul 2006)
New Revision: 9663
Modified:
trunk/apps/Thaw/src/thaw/fcp/FCPClientGet.java
trunk/apps/Thaw/src/thaw/fcp/FCPClientPut.java
trunk/apps/Thaw/src/thaw/fcp/FCPConnection.java
trunk/apps/Thaw/src/thaw/plugins/Console.java
Log:
Deadlock while getting many from the node seems to be solved
Modified: trunk/apps/Thaw/src/thaw/fcp/FCPClientGet.java
===================================================================
--- trunk/apps/Thaw/src/thaw/fcp/FCPClientGet.java 2006-07-19 12:21:02 UTC
(rev 9662)
+++ trunk/apps/Thaw/src/thaw/fcp/FCPClientGet.java 2006-07-19 19:32:52 UTC
(rev 9663)
@@ -40,10 +40,7 @@
private boolean running = false;
private boolean successful = false;
- private static boolean fetchLock = false;
- private boolean fetchLockOwner = false;
-
/**
* See setParameters().
*/
@@ -337,26 +334,22 @@
fileSize = message.getAmountOfDataWaiting();
- status = "Writing";
+ status = "Writing to disk";
setChanged();
notifyObservers();
-
//queueManager.getQueryManager().getConnection().lockWriting();
-
if(fetchDirectly(getPath(), fileSize, true)) {
successful = true;
status = "Available";
} else {
Logger.warning(this, "Unable to fetch correctly
the file. This may create problems on socket");
}
-
- fetchLock = false;
- fetchLockOwner = false;
-
-
//queueManager.getQueryManager().getConnection().unlockWriting();
+
queueManager.getQueryManager().getConnection().unlockReading();
+
queueManager.getQueryManager().getConnection().unlockWriting();
+
running = false;
progress = 100;
@@ -382,11 +375,13 @@
private class UnlockWaiter implements Runnable {
FCPClientGet clientGet;
+ FCPConnection connection;
String dir;
- public UnlockWaiter(FCPClientGet clientGet, String dir) {
+ public UnlockWaiter(FCPClientGet clientGet, FCPConnection
connection, String dir) {
this.clientGet = clientGet;
this.dir = dir;
+ this.connection = connection;
}
public void run() {
@@ -395,16 +390,30 @@
}
while(true) {
+ if(!connection.isReadingLocked()
+ && (!connection.isWritingLocked()))
+ break;
+
try {
Thread.sleep(200);
} catch(java.lang.InterruptedException e) {
}
+ }
+
+ if(!connection.lockReading()) {
+ /* Ah ben ou? mais non */
+ run();
+ }
- if(!fetchLock || fetchLockOwner)
- break;
+ if(!connection.lockWriting()) {
+ /* Ah ben ou? mais non */
+ connection.unlockReading();
+ run();
}
-
+
+ Logger.debug(this, "I take the reading lock !");
+
if(dir == null) {
Logger.warning(this, "UnlockWaiter.run() : Wtf
?");
}
@@ -442,7 +451,7 @@
notifyObservers();
- Thread fork = new Thread(new UnlockWaiter(this, dir));
+ Thread fork = new Thread(new UnlockWaiter(this,
queueManager.getQueryManager().getConnection(), dir));
fork.start();
return true;
@@ -460,9 +469,6 @@
Logger.warning(this, "saveFileTo() : Wtf ?");
}
- fetchLock = true;
- fetchLockOwner = true;
-
FCPMessage getRequestStatus = new FCPMessage();
getRequestStatus.setMessageName("GetRequestStatus");
@@ -475,7 +481,7 @@
- queueManager.getQueryManager().writeMessage(getRequestStatus);
+ queueManager.getQueryManager().writeMessage(getRequestStatus,
false);
return true;
}
Modified: trunk/apps/Thaw/src/thaw/fcp/FCPClientPut.java
===================================================================
--- trunk/apps/Thaw/src/thaw/fcp/FCPClientPut.java 2006-07-19 12:21:02 UTC
(rev 9662)
+++ trunk/apps/Thaw/src/thaw/fcp/FCPClientPut.java 2006-07-19 19:32:52 UTC
(rev 9663)
@@ -216,6 +216,11 @@
}
+ if(!connection.lockWriting()) {
+ /* Ah ben ou? mais non ... */
+ run();
+ }
+
clientPut.continueInsert();
return;
}
@@ -245,8 +250,6 @@
FCPConnection connection =
queueManager.getQueryManager().getConnection();
- connection.lockWriting();
-
status = "Sending to the node";
identifier = queueManager.getAnID() + "-"+ localFile.getName();
Modified: trunk/apps/Thaw/src/thaw/fcp/FCPConnection.java
===================================================================
--- trunk/apps/Thaw/src/thaw/fcp/FCPConnection.java 2006-07-19 12:21:02 UTC
(rev 9662)
+++ trunk/apps/Thaw/src/thaw/fcp/FCPConnection.java 2006-07-19 19:32:52 UTC
(rev 9663)
@@ -42,6 +42,7 @@
private long rawBytesWaiting = 0;
private boolean lockWriting = false;
+ private boolean lockReading = false;
private long lastWrite = 0; /* real writes ; System.currentTimeMillis()
*/
@@ -169,18 +170,58 @@
}
- public void lockWriting() {
+ public synchronized boolean lockWriting() {
+ if(lockWriting) {
+ Logger.notice(this, "Writing already locked! You can't
lock it !");
+ return false;
+ }
+
+ Logger.debug(this, "Lock writing ...");
lockWriting = true;
+
+ return true;
}
- public void unlockWriting() {
+ public synchronized boolean lockReading() {
+ if(lockReading) {
+ Logger.notice(this, "Reading already locked! You can't
lock it !");
+ return false;
+ }
+
+ Logger.debug(this, "Lock reading");
+ lockReading = true;
+
+ return true;
+ }
+
+ public synchronized void unlockWriting() {
+ if(!lockWriting) {
+ Logger.notice(this, "Writing already unlocked !");
+ return;
+ }
+
+ Logger.debug(this, "Unlock writting");
lockWriting = false;
}
+ public synchronized void unlockReading() {
+ if(!lockReading) {
+ Logger.notice(this, "Reading already unlocked !");
+ return;
+ }
+
+ Logger.debug(this, "Unlock reading");
+ lockReading = false;
+ }
+
public boolean isWritingLocked() {
return lockWriting;
}
+ public boolean isReadingLocked() {
+ return lockReading;
+ }
+
/**
* Doesn't check the lock state ! You have to manage it yourself.
*/
@@ -225,11 +266,11 @@
public boolean write(String toWrite, boolean checkLock) {
- if(checkLock && lockWriting) {
+ if(checkLock && isWritingLocked()) {
Logger.verbose(this, "Writting lock, unable to write.");
}
- while(checkLock && lockWriting) {
+ while(checkLock && isWritingLocked()) {
try {
Thread.sleep(200);
} catch(java.lang.InterruptedException e) {
Modified: trunk/apps/Thaw/src/thaw/plugins/Console.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/Console.java 2006-07-19 12:21:02 UTC
(rev 9662)
+++ trunk/apps/Thaw/src/thaw/plugins/Console.java 2006-07-19 19:32:52 UTC
(rev 9663)
@@ -34,7 +34,7 @@
private JLabel sizeLabel;
private JTextField sizeField;
- private long maxLogSize = 25600;
+ private long maxLogSize = 5120;
public boolean run(Core core) {
this.core = core;