Permalink
Browse files

Reserve timeout, part 1.

If we are already within the safety margin and the client issues a new
reserve command, just respond with the timeout message.
  • Loading branch information...
1 parent ad38067 commit f96ee87c8fa2d13e6fdc7fea73d0969f52b1deb9 Keith Rarick committed Mar 7, 2008
Showing with 26 additions and 2 deletions.
  1. +13 −0 conn.c
  2. +1 −0 conn.h
  3. +9 −2 doc/protocol.txt
  4. +3 −0 prot.c
View
13 conn.c
@@ -26,6 +26,8 @@
#include "util.h"
#include "prot.h"
+#define SAFETY_MARGIN 1 /* seconds */
+
/* Doubly-linked list of free connections. */
static struct conn pool = { &pool, &pool, 0 };
@@ -226,6 +228,17 @@ has_reserved_this_job(conn c, job needle)
return 0;
}
+/* return true if c has a reserved job with less than one second until its
+ * deadline */
+int
+conn_has_close_deadline(conn c)
+{
+ time_t t = time(NULL);
+ job j = soonest_job(c);
+
+ return j && t >= j->deadline - SAFETY_MARGIN;
+}
+
void
conn_close(conn c)
{
View
1 conn.h
@@ -107,5 +107,6 @@ void conn_set_worker(conn c);
job soonest_job(conn c);
int has_reserved_this_job(conn c, job j);
+int conn_has_close_deadline(conn c);
#endif /*conn_h*/
View
@@ -200,8 +200,15 @@ is reserved for the client, the client has limited time to run the job before
the job times out, when the server will put the job back into the ready queue.
The time available can be found by asking the server for the job's stats.
-There is only one possible response in the form of a text line followed by the
-job body:
+If the client has previously reserved job J and issues a reserve command when
+J has less than one second left in its ttr interval, the server will respond
+with:
+
+TIMEOUT\r\n
+
+This gives the client a chance to delete or release job J before the server
+automatically releases it. Otherwise, the only response is in the form of a
+text line followed by the job body:
RESERVED <id> <bytes>\r\n
<data>\r\n
View
3 prot.c
@@ -84,6 +84,7 @@
#define MSG_FOUND "FOUND"
#define MSG_NOTFOUND "NOT_FOUND\r\n"
#define MSG_RESERVED "RESERVED"
+#define MSG_TIMEOUT "TIMEOUT\r\n"
#define MSG_DELETED "DELETED\r\n"
#define MSG_RELEASED "RELEASED\r\n"
#define MSG_BURIED "BURIED\r\n"
@@ -1073,6 +1074,8 @@ dispatch_cmd(conn c)
reserve_ct++; /* stats */
conn_set_worker(c);
+ if (conn_has_close_deadline(c)) return reply_msg(c, MSG_TIMEOUT);
+
/* try to get a new job for this guy */
wait_for_job(c);
process_queue();

0 comments on commit f96ee87

Please sign in to comment.