Skip to content

Commit

Permalink
Add (experimental) binlog support for persistence
Browse files Browse the repository at this point in the history
Binary log files are created in a directory. Each time a job
changes status a record will be written to the file.

Each job keeps a reference count on the binlog it was created in.
Logs are purged when their reference count hits zero and all
binlogs prior have also hit zero

On server startup the binary logs are replayed to create a queue
with all the jobs either in ready, delayed or buried state. Basically
similar to what it would look like if all clients just disconnected
  • Loading branch information
gbarr committed Nov 4, 2008
1 parent 2ae6b46 commit 705eafb
Show file tree
Hide file tree
Showing 8 changed files with 428 additions and 1 deletion.
3 changes: 2 additions & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ beanstalkd_SOURCES = beanstalkd.c \
primes.c \
prot.c \
tube.c \
binlog.c \
util.c

cutgen_CFLAGS = -D__LINUX__

EXTRA_DIST = conn.h job.h ms.h net.h pq.h primes.h prot.h stat.h tube.h util.h
EXTRA_DIST = conn.h job.h ms.h net.h pq.h primes.h prot.h stat.h tube.h util.h binlog.h

tests = $(abs_srcdir)/tests/test_conn.c \
$(abs_srcdir)/tests/test_job.c \
Expand Down
9 changes: 9 additions & 0 deletions beanstalkd.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include "net.h"
#include "util.h"
#include "prot.h"
#include "binlog.h"

static char *user = NULL;
static int detach = 0;
Expand Down Expand Up @@ -92,6 +93,7 @@ su(const char *user) {
void
exit_cleanly(int sig)
{
binlog_close();
exit(0);
}

Expand Down Expand Up @@ -152,6 +154,7 @@ usage(char *msg, char *arg)
"\n"
"Options:\n"
" -d detach\n"
" -b DIR binlog directory\n"
" -l ADDR listen on address (default is 0.0.0.0)\n"
" -p PORT listen on port (default is 11300)\n"
" -u USER become user and group\n"
Expand Down Expand Up @@ -223,6 +226,9 @@ opts(int argc, char **argv)
case 'u':
user = argv[++i];
break;
case 'b':
binlog_dir = argv[++i];
break;
case 'h':
usage(NULL, NULL);
default:
Expand Down Expand Up @@ -252,8 +258,11 @@ main(int argc, char **argv)
nudge_fd_limit();

unbrake((evh) h_accept);
prot_replay_binlog();
binlog_init();

event_dispatch();
binlog_close();
twarnx("got here for some reason");
return 0;
}
Loading

0 comments on commit 705eafb

Please sign in to comment.