Author: mrogers
Date: 2006-08-27 20:15:31 +0000 (Sun, 27 Aug 2006)
New Revision: 10289
Modified:
trunk/apps/load-balancing-sims/phase6/ChkRequestHandler.java
trunk/apps/load-balancing-sims/phase6/Node.java
trunk/apps/load-balancing-sims/phase6/Sim.java
Log:
Transfer timeouts
Modified: trunk/apps/load-balancing-sims/phase6/ChkRequestHandler.java
===================================================================
--- trunk/apps/load-balancing-sims/phase6/ChkRequestHandler.java
2006-08-27 19:56:53 UTC (rev 10288)
+++ trunk/apps/load-balancing-sims/phase6/ChkRequestHandler.java
2006-08-27 20:15:31 UTC (rev 10289)
@@ -10,7 +10,7 @@
public final static int REQUEST_SENT = 1;
public final static int ACCEPTED = 2;
public final static int TRANSFERRING = 3;
- public final static int FAILED = 4;
+ public final static int COMPLETED = 4;
public final int id; // The unique ID of the request
public final int key; // The requested key
@@ -65,8 +65,10 @@
private void handleChkDataFound (ChkDataFound df)
{
if (state != ACCEPTED) node.log (df + " out of order");
+ if (prev != null) prev.sendMessage (df); // Forward the message
state = TRANSFERRING;
- if (prev != null) prev.sendMessage (df); // Forward the message
+ // Wait 5 minutes for the transfer to complete
+ Event.schedule (this, 300.0, TRANSFER_TIMEOUT, next);
}
private void handleDataNotFound (DataNotFound dnf)
@@ -75,6 +77,7 @@
if (prev == null) node.log (this + " failed");
else prev.sendMessage (dnf); // Forward the message
node.chkRequestCompleted (id);
+ state = COMPLETED;
}
private void handleBlock (Block b)
@@ -91,6 +94,7 @@
node.storeChk (key);
if (prev == null) node.log (this + " succeeded");
node.chkRequestCompleted (id);
+ state = COMPLETED;
}
}
@@ -102,7 +106,7 @@
if (prev == null) node.log (this + " failed");
else prev.sendMessage (new RouteNotFound (id));
node.chkRequestCompleted (id);
- state = FAILED;
+ state = COMPLETED;
}
else {
node.log ("forwarding " + this + " to " + next.address);
@@ -154,7 +158,7 @@
{
if (p != next) return; // We've already moved on to another peer
if (state != REQUEST_SENT) return; // Peer has already answered
- node.log (this + " search timed out waiting for " + p);
+ node.log (this + " accepted timeout waiting for " + p);
forwardRequest(); // Try another peer
}
@@ -162,20 +166,42 @@
private void fetchTimeout (Peer p)
{
if (state != ACCEPTED) return; // Peer has already answered
- node.log (this + " transfer timed out waiting for " + p);
+ node.log (this + " fetch timeout waiting for " + p);
if (prev == null) node.log (this + " failed");
- else prev.sendMessage (new DataNotFound (id));
node.chkRequestCompleted (id);
+ state = COMPLETED;
}
+ // Event callback
+ private void transferTimeout (Peer p)
+ {
+ if (state != TRANSFERRING) return; // Transfer has completed
+ node.log (this + " transfer timeout waiting for " + p);
+ if (prev == null) node.log (this + " failed");
+ node.chkRequestCompleted (id);
+ state = COMPLETED;
+ }
+
// EventTarget interface
public void handleEvent (int type, Object data)
{
- if (type == ACCEPTED_TIMEOUT) acceptedTimeout ((Peer) data);
- else if (type == FETCH_TIMEOUT) fetchTimeout ((Peer) data);
+ switch (type) {
+ case ACCEPTED_TIMEOUT:
+ acceptedTimeout ((Peer) data);
+ break;
+
+ case FETCH_TIMEOUT:
+ fetchTimeout ((Peer) data);
+ break;
+
+ case TRANSFER_TIMEOUT:
+ transferTimeout ((Peer) data);
+ break;
+ }
}
// Each EventTarget class has its own event codes
private final static int ACCEPTED_TIMEOUT = 1;
private final static int FETCH_TIMEOUT = 2;
+ private final static int TRANSFER_TIMEOUT = 3;
}
Modified: trunk/apps/load-balancing-sims/phase6/Node.java
===================================================================
--- trunk/apps/load-balancing-sims/phase6/Node.java 2006-08-27 19:56:53 UTC
(rev 10288)
+++ trunk/apps/load-balancing-sims/phase6/Node.java 2006-08-27 20:15:31 UTC
(rev 10289)
@@ -139,18 +139,14 @@
log ("accepting " + r);
prev.sendMessage (new Accepted (r.id));
}
- // DEBUG
- if (faulty) {
- log ("DEBUG: dropping " + r);
- return;
- }
// If the key is in the store, return it
if (chkStore.get (r.key)) {
log ("key " + r.key + " found in CHK store");
if (prev == null) log (r + " succeeded locally");
else {
prev.sendMessage (new ChkDataFound (r.id));
- for (int i = 0; i < 32; i++)
+ // DEBUG
+ if (!faulty) for (int i = 0; i < 32; i++)
prev.sendMessage (new Block (r.id, i));
}
chkRequestCompleted (r.id);
@@ -163,7 +159,8 @@
if (prev == null) log (r + " succeeded locally");
else {
prev.sendMessage (new ChkDataFound (r.id));
- for (int i = 0; i < 32; i++)
+ // DEBUG
+ if (!faulty) for (int i = 0; i < 32; i++)
prev.sendMessage (new Block (r.id, i));
}
chkRequestCompleted (r.id);
Modified: trunk/apps/load-balancing-sims/phase6/Sim.java
===================================================================
--- trunk/apps/load-balancing-sims/phase6/Sim.java 2006-08-27 19:56:53 UTC
(rev 10288)
+++ trunk/apps/load-balancing-sims/phase6/Sim.java 2006-08-27 20:15:31 UTC
(rev 10289)
@@ -28,8 +28,9 @@
for (int i = 0; i < 4; i++) {
int key = Node.locationToKey (Math.random());
- // Half the requests will succeed, half will fail
+ // Half the requests will succeed, half will time out
if (i % 2 == 0) n3.storeChk (key);
+ else n2.storeChk (key);
Event.schedule (n0, 0.0, Node.GENERATE_REQUEST, key);
}