Author: toad
Date: 2006-07-03 22:15:04 +0000 (Mon, 03 Jul 2006)
New Revision: 9453
Modified:
trunk/freenet/src/freenet/node/CHKInsertSender.java
trunk/freenet/src/freenet/node/Node.java
trunk/freenet/src/freenet/node/Version.java
trunk/freenet/src/freenet/node/fcp/ClientGet.java
trunk/freenet/src/freenet/store/BerkeleyDBFreenetStore.java
Log:
855: Synchronization fixes.
Modified: trunk/freenet/src/freenet/node/CHKInsertSender.java
===================================================================
--- trunk/freenet/src/freenet/node/CHKInsertSender.java 2006-07-03 22:08:05 UTC
(rev 9452)
+++ trunk/freenet/src/freenet/node/CHKInsertSender.java 2006-07-03 22:15:04 UTC
(rev 9453)
@@ -532,22 +532,22 @@
Logger.minor(this, "Set status code: "+getStatusString()+" on "+uid);
// Now wait for transfers, or for downstream transfer notifications.
-
- if(cw != null) {
- while(!allTransfersCompleted) {
- try {
- wait(10*1000);
- } catch (InterruptedException e) {
- // Try again
+
+ synchronized(this) {
+ if(cw != null) {
+ while(!allTransfersCompleted) {
+ try {
+ wait(10*1000);
+ } catch (InterruptedException e) {
+ // Try again
+ }
}
+ } else {
+ // There weren't any transfers
+ allTransfersCompleted = true;
}
- } else {
- // There weren't any transfers
- synchronized(this) {
- allTransfersCompleted = true;
- }
+ notifyAll();
}
- notifyAll();
Logger.minor(this, "Returning from finish()");
}
Modified: trunk/freenet/src/freenet/node/Node.java
===================================================================
--- trunk/freenet/src/freenet/node/Node.java 2006-07-03 22:08:05 UTC (rev
9452)
+++ trunk/freenet/src/freenet/node/Node.java 2006-07-03 22:15:04 UTC (rev
9453)
@@ -1408,7 +1408,7 @@
System.err.println("Could not open store: "+e);
e.printStackTrace();
System.err.println("Attempting to
reconstruct...");
- WrapperManager.signalStarting(1000000);
+ WrapperManager.signalStarting(5*60*60*1000);
tmp = new
BerkeleyDBFreenetStore(storeDir.getPath()+File.separator+"store-"+portNumber,
maxStoreKeys, 32768, CHKBlock.TOTAL_HEADERS_LENGTH,
BerkeleyDBFreenetStore.TYPE_CHK);
}
chkDatastore = tmp;
@@ -1423,7 +1423,7 @@
System.err.println("Could not open store: "+e);
e.printStackTrace();
System.err.println("Attempting to
reconstruct...");
- WrapperManager.signalStarting(1000000);
+ WrapperManager.signalStarting(5*60*60*1000);
tmp = new
BerkeleyDBFreenetStore(storeDir.getPath()+File.separator+"pubkeystore-"+portNumber,
maxStoreKeys, DSAPublicKey.PADDED_SIZE, 0, BerkeleyDBFreenetStore.TYPE_PUBKEY);
}
this.pubKeyDatastore = tmp;
Modified: trunk/freenet/src/freenet/node/Version.java
===================================================================
--- trunk/freenet/src/freenet/node/Version.java 2006-07-03 22:08:05 UTC (rev
9452)
+++ trunk/freenet/src/freenet/node/Version.java 2006-07-03 22:15:04 UTC (rev
9453)
@@ -18,7 +18,7 @@
public static final String protocolVersion = "1.0";
/** The build number of the current revision */
- private static final int buildNumber = 854;
+ private static final int buildNumber = 855;
/** Oldest build of Fred we will talk to */
private static final int oldLastGoodBuild = 839;
Modified: trunk/freenet/src/freenet/node/fcp/ClientGet.java
===================================================================
--- trunk/freenet/src/freenet/node/fcp/ClientGet.java 2006-07-03 22:08:05 UTC
(rev 9452)
+++ trunk/freenet/src/freenet/node/fcp/ClientGet.java 2006-07-03 22:15:04 UTC
(rev 9453)
@@ -306,10 +306,12 @@
finish();
}
- private synchronized void
trySendDataFoundOrGetFailed(FCPConnectionOutputHandler handler) {
+ private void trySendDataFoundOrGetFailed(FCPConnectionOutputHandler
handler) {
FCPMessage msg;
-
+
+ // Don't need to lock. succeeded is only ever set, never unset.
+ // and succeeded and getFailedMessage are both atomic.
if(succeeded) {
msg = new DataFoundMessage(foundDataLength,
foundDataMimeType, identifier);
} else {
@@ -386,7 +388,8 @@
// Ignore
}
- public synchronized void receive(ClientEvent ce) {
+ public void receive(ClientEvent ce) {
+ // Don't need to lock, verbosity is final and finished is never
unset.
if(finished) return;
if(!(((verbosity & VERBOSITY_SPLITFILE_PROGRESS) ==
VERBOSITY_SPLITFILE_PROGRESS) &&
(ce instanceof SplitfileProgressEvent)))
@@ -414,13 +417,6 @@
fs.put("TempFilename", tempFile.getPath());
if(clientToken != null)
fs.put("ClientToken", clientToken);
- //FIXME: what were we supposed to do there ?
- if(returnType == ClientGetMessage.RETURN_TYPE_DISK &&
targetFile != null) {
- // Otherwise we must re-run it anyway as we don't have
the data.
-
- // finished => persistence of completion state, pending
messages
- //fs.put("Finished", Boolean.toString(finished));
- }
fs.put("IgnoreDS", Boolean.toString(fctx.ignoreStore));
fs.put("DSOnly", Boolean.toString(fctx.localRequestOnly));
fs.put("MaxRetries",
Integer.toString(fctx.maxNonSplitfileRetries));
Modified: trunk/freenet/src/freenet/store/BerkeleyDBFreenetStore.java
===================================================================
--- trunk/freenet/src/freenet/store/BerkeleyDBFreenetStore.java 2006-07-03
22:08:05 UTC (rev 9452)
+++ trunk/freenet/src/freenet/store/BerkeleyDBFreenetStore.java 2006-07-03
22:15:04 UTC (rev 9453)
@@ -235,15 +235,22 @@
private void maybeShrink(boolean dontCheck) throws DatabaseException,
IOException {
Transaction t = null;
try {
- if(maxChkBlocks >= chkBlocksInStore)
- return;
+ // long's are not atomic.
+ long maxBlocks;
+ long curBlocks;
+ synchronized(this) {
+ maxBlocks = maxChkBlocks;
+ curBlocks = chkBlocksInStore;
+ if(maxBlocks >= curBlocks)
+ return;
+ }
System.err.println("Shrinking store:
"+chkBlocksInStore+" -> "+maxChkBlocks);
Logger.error(this, "Shrinking store:
"+chkBlocksInStore+" -> "+maxChkBlocks);
while(true) {
t = environment.beginTransaction(null,null);
long deleted = 0;
- for(long
i=chkBlocksInStore-1;i>=maxChkBlocks;i--) {
-
+ for(long i=curBlocks-1;i>=maxBlocks;i--) {
+
// Delete the block with this blocknum.
Long blockNo = new Long(i);
@@ -254,6 +261,13 @@
chkDB_blockNum.delete(t,
blockNumEntry);
if(result.equals(OperationStatus.SUCCESS))
deleted++;
+
+ synchronized(this) {
+ maxBlocks = maxChkBlocks;
+ curBlocks = chkBlocksInStore;
+ if(maxBlocks >= curBlocks)
+ return;
+ }
}
t.commit();
@@ -263,8 +277,15 @@
t = null;
if(deleted == 0 || dontCheck) break;
- else
+ else {
System.err.println("Checking...");
+ synchronized(this) {
+ maxBlocks = maxChkBlocks;
+ curBlocks = chkBlocksInStore;
+ if(maxBlocks >= curBlocks)
+ return;
+ }
+ }
}
chkStore.setLength(maxChkBlocks * (dataBlockSize +
headerBlockSize));
@@ -1298,8 +1319,10 @@
}
}
- public synchronized void setMaxKeys(long maxStoreKeys) throws
DatabaseException, IOException {
- maxChkBlocks = maxStoreKeys;
+ public void setMaxKeys(long maxStoreKeys) throws DatabaseException,
IOException {
+ synchronized(this) {
+ maxChkBlocks = maxStoreKeys;
+ }
maybeShrink(false);
}
}