Author: toad
Date: 2006-08-04 23:46:05 +0000 (Fri, 04 Aug 2006)
New Revision: 9891
Added:
trunk/freenet/src/freenet/client/async/SimpleSendableInsert.java
Modified:
trunk/freenet/src/freenet/client/async/SendableInsert.java
trunk/freenet/src/freenet/keys/ClientKeyBlock.java
trunk/freenet/src/freenet/node/Node.java
trunk/freenet/src/freenet/node/RequestSender.java
trunk/freenet/src/freenet/node/Version.java
Log:
926: 1 in 200 successful requests (not satisfied by local store) starts an
insert of the content just fetched.
This is the first phase of the storage changes.
Modified: trunk/freenet/src/freenet/client/async/SendableInsert.java
===================================================================
--- trunk/freenet/src/freenet/client/async/SendableInsert.java 2006-08-04
22:45:55 UTC (rev 9890)
+++ trunk/freenet/src/freenet/client/async/SendableInsert.java 2006-08-04
23:46:05 UTC (rev 9891)
@@ -11,12 +11,6 @@
*/
public interface SendableInsert extends SendableRequest {
- /** Get the ClientKeyBlock to insert. This may be created
- * just-in-time, and may return null; ClientRequestScheduler
- * will simply unregister the SendableInsert if this happens.
- */
- public ClientKeyBlock getBlock();
-
/** Called when we successfully insert the data */
public void onSuccess();
Added: trunk/freenet/src/freenet/client/async/SimpleSendableInsert.java
===================================================================
--- trunk/freenet/src/freenet/client/async/SimpleSendableInsert.java
2006-08-04 22:45:55 UTC (rev 9890)
+++ trunk/freenet/src/freenet/client/async/SimpleSendableInsert.java
2006-08-04 23:46:05 UTC (rev 9891)
@@ -0,0 +1,72 @@
+package freenet.client.async;
+
+import freenet.keys.ClientKeyBlock;
+import freenet.keys.KeyBlock;
+import freenet.node.LowLevelPutException;
+import freenet.node.Node;
+import freenet.support.Logger;
+
+/**
+ * Simple SendableInsert implementation. No feedback, no retries, just insert
the
+ * block. Not designed for use by the client layer. Used by the node layer for
the
+ * 1 in every 200 successful requests which starts an insert.
+ */
+public class SimpleSendableInsert implements SendableInsert {
+
+ public final Node node;
+ public final KeyBlock block;
+ public final short prioClass;
+ private boolean finished;
+
+ public SimpleSendableInsert(Node node, KeyBlock block, short prioClass)
{
+ this.node = node;
+ this.block = block;
+ this.prioClass = prioClass;
+ }
+
+ public void onSuccess() {
+ // Yay!
+ Logger.minor(this, "Finished insert of "+block);
+ }
+
+ public void onFailure(LowLevelPutException e) {
+ Logger.minor(this, "Failed insert of "+block+": "+e);
+ }
+
+ public short getPriorityClass() {
+ return prioClass;
+ }
+
+ public int getRetryCount() {
+ // No retries.
+ return 0;
+ }
+
+ public void send(Node node) {
+ try {
+ Logger.minor(this, "Starting request: "+this);
+ node.realPut(block, false);
+ } catch (LowLevelPutException e) {
+ onFailure(e);
+ Logger.minor(this, "Request failed: "+this+" for "+e);
+ return;
+ } finally {
+ finished = true;
+ }
+ Logger.minor(this, "Request succeeded: "+this);
+ onSuccess();
+ }
+
+ public Object getClient() {
+ return node;
+ }
+
+ public ClientRequester getClientRequest() {
+ return null;
+ }
+
+ public boolean isFinished() {
+ return finished;
+ }
+
+}
Modified: trunk/freenet/src/freenet/keys/ClientKeyBlock.java
===================================================================
--- trunk/freenet/src/freenet/keys/ClientKeyBlock.java 2006-08-04 22:45:55 UTC
(rev 9890)
+++ trunk/freenet/src/freenet/keys/ClientKeyBlock.java 2006-08-04 23:46:05 UTC
(rev 9891)
@@ -5,7 +5,7 @@
import freenet.support.io.Bucket;
import freenet.support.io.BucketFactory;
-public interface ClientKeyBlock {
+public interface ClientKeyBlock extends KeyBlock {
/** Decode with the key
* @param factory The BucketFactory to use to create the Bucket to
return the data in.
Modified: trunk/freenet/src/freenet/node/Node.java
===================================================================
--- trunk/freenet/src/freenet/node/Node.java 2006-08-04 22:45:55 UTC (rev
9890)
+++ trunk/freenet/src/freenet/node/Node.java 2006-08-04 23:46:05 UTC (rev
9891)
@@ -48,6 +48,7 @@
import freenet.client.async.ClientRequestScheduler;
import freenet.client.async.HealingQueue;
import freenet.client.async.SimpleHealingQueue;
+import freenet.client.async.SimpleSendableInsert;
import freenet.client.async.USKManager;
import freenet.client.events.SimpleEventProducer;
import freenet.clients.http.BookmarkManager;
@@ -2046,16 +2047,16 @@
}
}
- public void realPut(ClientKeyBlock block, boolean cache) throws
LowLevelPutException {
- if(block instanceof ClientCHKBlock)
- realPutCHK((ClientCHKBlock)block, cache);
- else if(block instanceof ClientSSKBlock)
- realPutSSK((ClientSSKBlock)block, cache);
+ public void realPut(KeyBlock block, boolean cache) throws
LowLevelPutException {
+ if(block instanceof CHKBlock)
+ realPutCHK((CHKBlock)block, cache);
+ else if(block instanceof SSKBlock)
+ realPutSSK((SSKBlock)block, cache);
else
throw new IllegalArgumentException("Unknown put type
"+block.getClass());
}
- public void realPutCHK(ClientCHKBlock block, boolean cache) throws
LowLevelPutException {
+ public void realPutCHK(CHKBlock block, boolean cache) throws
LowLevelPutException {
byte[] data = block.getData();
byte[] headers = block.getHeaders();
PartiallyReceivedBlock prb = new
PartiallyReceivedBlock(PACKETS_IN_BLOCK, PACKET_SIZE, data);
@@ -2073,7 +2074,7 @@
Logger.error(this, "Datastore failure: "+e, e);
}
}
- is =
makeInsertSender((NodeCHK)block.getClientKey().getNodeKey(),
+ is = makeInsertSender((NodeCHK)block.getKey(),
MAX_HTL, uid, null, headers, prb, false,
lm.getLocation().getValue(), cache);
boolean hasReceivedRejectedOverload = false;
// Wait for status
@@ -2168,7 +2169,7 @@
}
}
- public void realPutSSK(ClientSSKBlock block, boolean cache) throws
LowLevelPutException {
+ public void realPutSSK(SSKBlock block, boolean cache) throws
LowLevelPutException {
SSKInsertSender is;
long uid = random.nextLong();
if(!lockUID(uid)) {
@@ -3645,4 +3646,15 @@
public HealingQueue getHealingQueue() {
return healingQueue;
}
+
+ public void queueRandomReinsert(KeyBlock block) {
+ SimpleSendableInsert ssi = new SimpleSendableInsert(this,
block, RequestStarter.MAXIMUM_PRIORITY_CLASS);
+ Logger.minor(this, "Queueing random reinsert for "+block+" :
"+ssi);
+ if(block instanceof CHKBlock)
+ chkPutScheduler.register(ssi);
+ else if(block instanceof SSKBlock)
+ sskPutScheduler.register(ssi);
+ else
+ Logger.error(this, "Don't know what to do with
"+block+" should be queued for reinsert");
+ }
}
Modified: trunk/freenet/src/freenet/node/RequestSender.java
===================================================================
--- trunk/freenet/src/freenet/node/RequestSender.java 2006-08-04 22:45:55 UTC
(rev 9890)
+++ trunk/freenet/src/freenet/node/RequestSender.java 2006-08-04 23:46:05 UTC
(rev 9891)
@@ -39,6 +39,9 @@
// Constants
static final int ACCEPTED_TIMEOUT = 5000;
static final int FETCH_TIMEOUT = 60000;
+ /** One in this many successful requests is randomly reinserted.
+ * This is probably a good idea anyway but with the split store it's
essential. */
+ static final int RANDOM_REINSERT_INTERVAL = 200;
// Basics
final Key key;
@@ -395,6 +398,8 @@
try {
block = new SSKBlock(sskData, headers, (NodeSSK)key,
false);
node.store(block);
+ if(node.random.nextInt(RANDOM_REINSERT_INTERVAL) == 0)
+ node.queueRandomReinsert(block);
finish(SUCCESS, next);
} catch (SSKVerifyException e) {
Logger.error(this, "Failed to verify: "+e+" from
"+next, e);
@@ -428,7 +433,10 @@
private void verifyAndCommit(byte[] data) throws KeyVerifyException {
if(key instanceof NodeCHK) {
- node.store(new CHKBlock(data, headers, (NodeCHK)key));
+ CHKBlock block = new CHKBlock(data, headers, (NodeCHK)key);
+ node.store(block);
+ if(node.random.nextInt(RANDOM_REINSERT_INTERVAL) == 0)
+ node.queueRandomReinsert(block);
} else if (key instanceof NodeSSK) {
try {
node.store(new SSKBlock(data, headers,
(NodeSSK)key, false));
Modified: trunk/freenet/src/freenet/node/Version.java
===================================================================
--- trunk/freenet/src/freenet/node/Version.java 2006-08-04 22:45:55 UTC (rev
9890)
+++ trunk/freenet/src/freenet/node/Version.java 2006-08-04 23:46:05 UTC (rev
9891)
@@ -18,7 +18,7 @@
public static final String protocolVersion = "1.0";
/** The build number of the current revision */
- private static final int buildNumber = 925;
+ private static final int buildNumber = 926;
/** Oldest build of Fred we will talk to */
private static final int oldLastGoodBuild = 874;