Skip to content

Commit

Permalink
Rename dqlite to dqlite_task
Browse files Browse the repository at this point in the history
  • Loading branch information
freeekanayaka committed Aug 24, 2019
1 parent c22d01c commit e76a24a
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 42 deletions.
3 changes: 1 addition & 2 deletions .dir-locals.el
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
((nil . ((fill-column . 80)))
(c-mode . ((c-file-style . "linux-tabs-only")
(flycheck-gcc-definitions . ("_GNU_SOURCE"))
(flycheck-clang-definitions . ("_GNU_SOURCE"))
(flycheck-gcc-include-path . ("../include")))))
(flycheck-clang-definitions . ("_GNU_SOURCE")))))
27 changes: 14 additions & 13 deletions include/dqlite.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ struct dqlite_server
};

/* Handle connections from dqlite clients */
typedef struct dqlite dqlite;
typedef struct dqlite_task dqlite_task;

typedef int (*dqlite_connect)(void *data,
const struct dqlite_server *server,
Expand All @@ -94,11 +94,10 @@ typedef int (*dqlite_connect)(void *data,
/* Allocate and initialize a dqlite server instance. */
int dqlite_create(unsigned id,
const char *address,
const char *dir,
dqlite **d);
const char *dir, dqlite_task **t);

/* Destroy and deallocate a dqlite server instance. */
void dqlite_destroy(dqlite *d);
void dqlite_destroy(dqlite_task *t);

/* Function to emit log messages. */
typedef void (*dqlite_emit)(void *data,
Expand All @@ -114,9 +113,9 @@ typedef void (*dqlite_watch)(void *data, int old_state, int new_state);
* This API must be called after dqlite_init and before
* dqlite_run.
*/
int dqlite_config(dqlite *d, int op, ...);
int dqlite_config(dqlite_task *t, int op, ...);

int dqlite_bootstrap(dqlite *d,
int dqlite_bootstrap(dqlite_task *t,
unsigned n,
const struct dqlite_server *servers);

Expand All @@ -125,7 +124,7 @@ int dqlite_bootstrap(dqlite *d,
* In case of error, a human-readable message describing the failure can be
* obtained using dqlite_errmsg.
*/
int dqlite_run(dqlite *d);
int dqlite_run(dqlite_task *t);

/* Wait until a dqlite server is ready and can handle connections.
**
Expand All @@ -134,20 +133,22 @@ int dqlite_run(dqlite *d);
** This is a thread-safe API, but must be invoked before any call to
** dqlite_stop or dqlite_handle.
*/
bool dqlite_ready(dqlite *d);
bool dqlite_ready(dqlite_task *t);

/* Return information about all servers currently part of the dqlite cluster.
*
* In case of success, the caller is responsible for freeing the returned array
* using sqlite3_free(). */
int dqlite_cluster(dqlite *d, struct dqlite_server *servers[], unsigned *n);
int dqlite_cluster(dqlite_task *t,
struct dqlite_server *servers[],
unsigned *n);

/* Fill the given struct with info about the current cluster leader. Return
* false if no leader is currently known. */
bool dqlite_leader(dqlite *d, struct dqlite_server *server);
bool dqlite_leader(dqlite_task *t, struct dqlite_server *server);

/* Dump the content of a database file. */
int dqlite_dump(dqlite *d, const char *filename, void **buf, size_t *len);
int dqlite_dump(dqlite_task *t, const char *filename, void **buf, size_t *len);

/* Stop a dqlite server.
**
Expand All @@ -156,7 +157,7 @@ int dqlite_dump(dqlite *d, const char *filename, void **buf, size_t *len);
** In case of error, the caller must invoke sqlite3_free
** against the returned errmsg.
*/
int dqlite_stop(dqlite *d);
int dqlite_stop(dqlite_task *t);

/* Start handling a new connection.
**
Expand All @@ -165,6 +166,6 @@ int dqlite_stop(dqlite *d);
** In case of error, the caller must invoke sqlite3_free
** against the returned errmsg.
*/
int dqlite_handle(dqlite *d, int fd);
int dqlite_handle(dqlite_task *t, int fd);

#endif /* DQLITE_H */
4 changes: 2 additions & 2 deletions src/lib/buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
* TODO: consider using mremap.
*/

#include <unistd.h>

#ifndef LIB_BUFFER_H_
#define LIB_BUFFER_H_

#include <unistd.h>

struct buffer
{
void *data; /* Allocated buffer */
Expand Down
40 changes: 20 additions & 20 deletions src/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ static int convertRaftState(int state)
/* Invoke the configured state watch function, if any. */
static void raftWatch(struct raft *r, int old_state)
{
struct dqlite *d = r->data;
struct dqlite_task *d = r->data;
int new_state = raft_state(r);

if (d->config.watcher.f != NULL) {
Expand Down Expand Up @@ -131,12 +131,12 @@ void raftRingLoggerWalkCb(void *data,
}

/* Bump raft's ring logger to stdout. */
static void dumpRaftRingLogger(struct dqlite *d)
static void dumpRaftRingLogger(struct dqlite_task *d)
{
raft_ring_logger_walk(&d->raft_logger, raftRingLoggerWalkCb, NULL);
}

int dqlite__init(struct dqlite *d,
int dqlite__init(struct dqlite_task *d,
unsigned id,
const char *address,
const char *dir)
Expand Down Expand Up @@ -234,7 +234,7 @@ int dqlite__init(struct dqlite *d,
return rv;
}

void dqlite__close(struct dqlite *d)
void dqlite__close(struct dqlite_task *d)
{
int rv;
rv = pthread_mutex_destroy(&d->mutex); /* This is a no-op on Linux . */
Expand All @@ -254,7 +254,7 @@ void dqlite__close(struct dqlite *d)
config__close(&d->config);
}

int dqlite_create(unsigned id, const char *address, const char *dir, dqlite **d)
int dqlite_create(unsigned id, const char *address, const char *dir, dqlite_task **d)
{
int rv;

Expand All @@ -268,13 +268,13 @@ int dqlite_create(unsigned id, const char *address, const char *dir, dqlite **d)
return 0;
}

void dqlite_destroy(dqlite *d)
void dqlite_destroy(dqlite_task *d)
{
dqlite__close(d);
sqlite3_free(d);
}

int dqlite_bootstrap(dqlite *d, unsigned n, const struct dqlite_server *servers)
int dqlite_bootstrap(dqlite_task *d, unsigned n, const struct dqlite_server *servers)
{
struct raft_configuration configuration;
unsigned i;
Expand Down Expand Up @@ -312,7 +312,7 @@ int dqlite_bootstrap(dqlite *d, unsigned n, const struct dqlite_server *servers)
*/
static void raftCloseCb(struct raft *raft)
{
struct dqlite *s = raft->data;
struct dqlite_task *s = raft->data;
uv_close((struct uv_handle_s *)&s->stop, NULL);
uv_close((struct uv_handle_s *)&s->incoming, NULL);
uv_close((struct uv_handle_s *)&s->startup, NULL);
Expand All @@ -324,7 +324,7 @@ static void destroy_conn(struct conn *conn)
sqlite3_free(conn);
}

static void process_incoming(struct dqlite *d)
static void process_incoming(struct dqlite_task *d)
{
while (!QUEUE__IS_EMPTY(&d->queue)) {
queue *head;
Expand Down Expand Up @@ -356,7 +356,7 @@ static void process_incoming(struct dqlite *d)

static void stop_cb(uv_async_t *stop)
{
struct dqlite *d = stop->data;
struct dqlite_task *d = stop->data;
queue *head;
struct conn *conn;

Expand Down Expand Up @@ -384,7 +384,7 @@ static void stop_cb(uv_async_t *stop)
*/
static void incoming_cb(uv_async_t *incoming)
{
struct dqlite *d = incoming->data;
struct dqlite_task *d = incoming->data;
/* Acquire the queue lock, so no new incoming connection can be
* pushed. */
pthread_mutex_lock(&d->mutex);
Expand All @@ -398,14 +398,14 @@ static void incoming_cb(uv_async_t *incoming)
*/
static void startup_cb(uv_timer_t *startup)
{
struct dqlite *d = startup->data;
struct dqlite_task *d = startup->data;
int rv;
d->running = true;
rv = sem_post(&d->ready);
assert(rv == 0); /* No reason for which posting should fail */
}

int dqlite_run(struct dqlite *d)
int dqlite_run(struct dqlite_task *d)
{
int rv;

Expand Down Expand Up @@ -445,14 +445,14 @@ int dqlite_run(struct dqlite *d)
return 0;
}

bool dqlite_ready(struct dqlite *d)
bool dqlite_ready(struct dqlite_task *d)
{
/* Wait for the ready semaphore */
sem_wait(&d->ready);
return d->running;
}

int dqlite_handle(dqlite *d, int fd)
int dqlite_handle(dqlite_task *d, int fd)
{
struct incoming *incoming;
int rv;
Expand Down Expand Up @@ -489,7 +489,7 @@ int dqlite_handle(dqlite *d, int fd)
return 0;
}

int dqlite_stop(dqlite *d)
int dqlite_stop(dqlite_task *d)
{
int rv;

Expand All @@ -512,7 +512,7 @@ int dqlite_stop(dqlite *d)
}

/* Set a config option */
int dqlite_config(struct dqlite *d, int op, ...)
int dqlite_config(struct dqlite_task *d, int op, ...)
{
va_list args;
dqlite_connect connectFunc;
Expand Down Expand Up @@ -552,7 +552,7 @@ int dqlite_config(struct dqlite *d, int op, ...)
return rv;
}

int dqlite_cluster(dqlite *d, struct dqlite_server *servers[], unsigned *n)
int dqlite_cluster(dqlite_task *d, struct dqlite_server *servers[], unsigned *n)
{
unsigned i;
/* TODO: this is not thread-safe, we should use an async handle */
Expand All @@ -570,14 +570,14 @@ int dqlite_cluster(dqlite *d, struct dqlite_server *servers[], unsigned *n)
return 0;
}

bool dqlite_leader(dqlite *d, struct dqlite_server *server)
bool dqlite_leader(dqlite_task *d, struct dqlite_server *server)
{
/* TODO: this is not thread-safe, we should use an async handle */
raft_leader(&d->raft, &server->id, &server->address);
return server->id != 0;
}

int dqlite_dump(dqlite *d, const char *filename, void **buf, size_t *len)
int dqlite_dump(dqlite_task *d, const char *filename, void **buf, size_t *len)
{
return vfsFileRead(d->config.name, filename, buf, len);
}
8 changes: 4 additions & 4 deletions src/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
/**
* A single dqlite server instance.
*/
struct dqlite
struct dqlite_task
{
struct config config; /* Config values */
struct sqlite3_vfs vfs; /* In-memory VFS */
Expand All @@ -33,11 +33,11 @@ struct dqlite
uv_timer_t startup; /* Unblock ready sem */
};

int dqlite__init(struct dqlite *d,
int dqlite__init(struct dqlite_task *d,
unsigned id,
const char *address,
const char *dir);

void dqlite__close(struct dqlite *d);
void dqlite__close(struct dqlite_task *d);

int dqlite__run(struct dqlite *d);
int dqlite__run(struct dqlite_task *d);
2 changes: 1 addition & 1 deletion test/lib/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ struct test_server
char address[8]; /* Server address. */
char *dir; /* Data directory. */
struct test_endpoint endpoint; /* For network connections. */
dqlite *dqlite; /* Dqlite instance. */
dqlite_task *dqlite; /* Dqlite instance. */
pthread_t run; /* Main run loop thread. */
struct client client; /* Connected client. */
struct test_server *others[5]; /* Other servers, by ID-1. */
Expand Down

0 comments on commit e76a24a

Please sign in to comment.