Skip to content

Commit

Permalink
Add gos_interval.
Browse files Browse the repository at this point in the history
Add a second yaml file for testing.
Some code cleanups
  • Loading branch information
timiblossom committed Mar 5, 2014
1 parent ceebbfc commit 30062fa
Show file tree
Hide file tree
Showing 10 changed files with 76 additions and 120 deletions.
36 changes: 17 additions & 19 deletions conf/dynomite.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
local_memcached:
listen: 0.0.0.0:7102
hash: fnv1a_64
distribution: ketama
preconnect: true
dyn_o_mite:
auto_eject_hosts: false
server_retry_timeout: 2000
timeout: 1500
servers:
- 127.0.0.1:11211:1

datacenter: DC1
distribution: vnode
dyn_listen: 127.0.0.1:8101
dyn_read_timeout: 200000
dyn_seed_provider: simple_provider
dyn_seeds:
- ec2-107-20-60-79.compute-1.amazonaws.com:7101:1
- ec2-23-22-95-236.compute-1.amazonaws.com:7101:1
- ec2-54-226-224-148.compute-1.amazonaws.com:7101:1

#dyn_port: 33331
dyn_listen: 0.0.0.0:7101
dyn_read_timeout: 2000
dyn_write_timeout: 2000
dyn_seeds:
- 127.0.0.2:8101:DC1:5622637,721812480,851406979,1036155118,2147653893,2233516174
dyn_write_timeout: 200000
gos_interval: 10000
hash: murmur
listen: 127.0.0.1:8102
preconnect: true
server_retry_timeout: 200000
servers:
- 127.0.0.1:11211:1
timeout: 150000
tokens: 437425602,1122629340,1683099499,2400294391,2772631304,4271597971
19 changes: 19 additions & 0 deletions conf/dynomite2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
dyn_o_mite:
auto_eject_hosts: false
datacenter: DC1
distribution: vnode
dyn_listen: 127.0.0.2:8101
dyn_read_timeout: 200000
dyn_seed_provider: simple_provider
dyn_seeds:
- 127.0.0.1:8101:DC1:437425602,1122629340,1683099499,2400294391,2772631304,4271597971
dyn_write_timeout: 200000
gos_interval: 10000
hash: murmur
listen: 127.0.0.2:8102
preconnect: true
server_retry_timeout: 200000
servers:
- 127.0.0.1:11211:1
timeout: 150000
tokens: 5622637,721812480,851406979,1036155118,2147653893,2233516174
2 changes: 1 addition & 1 deletion src/dyn_message.c
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ dyn_parse_req(struct msg *r)

error:
loga("at error");
r->result = DMSG_PARSE_ERROR;
r->result = MSG_PARSE_ERROR;
r->state = state;
errno = EINVAL;

Expand Down
1 change: 1 addition & 0 deletions src/dyn_message.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ typedef enum dmsg_type {
DMSG_REQ_MC_READ, /* memcache retrieval requests */
DMSG_REQ_MC_WRITE,
DMSG_REQ_MC_DELETE,
GOSSIP_PING,
GOSSIP_DIGEST_SYN,
GOSSIP_DIGEST_ACK,
GOSSIP_DIGEST_ACK2,
Expand Down
4 changes: 2 additions & 2 deletions src/dyn_peer.c
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ dyn_peer_add_local(struct server_pool *pool, struct peer *peer)
peer->is_seed = 1;
peer->owner = pool;

log_debug(LOG_VERB, "transform to local node to peer %"PRIu32" '%.*s'",
log_debug(LOG_VERB, "dyn: transform to local node to peer %"PRIu32" '%.*s'",
peer->idx, pool->name.len, pool->name.data);

return NC_OK;
Expand All @@ -150,7 +150,7 @@ dyn_peer_init(struct array *conf_seeds,
/* init seeds list */
nseed = array_n(conf_seeds);
if(nseed == 0) {
log_debug(LOG_INFO, "look like you are running with no seeds deifined. This is ok for running with just one node.");
log_debug(LOG_INFO, "dyn: look like you are running with no seeds deifined. This is ok for running with just one node.");

// add current node to peers array
status = array_init(peers, 1, sizeof(struct peer));
Expand Down
48 changes: 10 additions & 38 deletions src/dyn_ring.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,46 +8,18 @@
#include <nc_server.h>
#include <dyn_token.h>

static rstatus_t
dyn_ring_each_set_owner(void *elem, void *data)
{
struct ring_node *rn = elem;
struct server_pool *sp = data;

rn->owner = sp;

return NC_OK;
}

rstatus_t
dyn_ring_init(struct array *conf_seeds, struct server_pool *sp)
rstatus_t dyn_ring_init(struct array *peers, struct server_pool *sp)
{
uint32_t seed_cnt = array_n(conf_seeds);
if(seed_cnt == 0) {
return NC_OK;
}

struct array *nodes = &sp->ring.ring_nodes;

rstatus_t status = array_init(nodes, seed_cnt, sizeof(struct ring_node));
if (status != NC_OK) {
return status;
}
sp->ring.ring_nodes = peers;
sp->ring.owner = sp;

return NC_OK;
}

/* transform conf seeds to ring_nodes */
status = array_each(conf_seeds, conf_seed_ring_each_transform, nodes);
if (status != NC_OK) {
//TODO: do some deinit'ing here on barf time
//dyn_peer_deinit(seeds);
return status;
}
ASSERT(array_n(nodes) == seed_cnt);

status = array_each(nodes, dyn_ring_each_set_owner, sp);
if (status != NC_OK) {
//TODO: do some deinit'ing here on barf time
return status;
}

return NC_OK;
rstatus_t dyn_gos_run(struct context *ctx)
{
loga("Running gossip serviceeeeeeeeeeeeeeeeeeeeeeeeeee");
return NC_OK;
}
27 changes: 3 additions & 24 deletions src/dyn_ring.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,11 @@

#include <nc_core.h>

struct ring_node {
struct server_pool *owner; /* owner pool */

struct string pname; /* name:port:weight (ref in conf_server) */
struct string name; /* name (ref in conf_server) */
uint16_t port; /* port */
int family; /* socket family */
socklen_t addrlen; /* socket length */
struct sockaddr *addr; /* socket address (ref in conf_server) */

uint32_t ns_conn_q; /* #peer connection */
struct conn_tqh s_conn_q; /* peer connection q */

// this is where, is suspect, we'll keep things like gossip's vclock,
// and other, node-specific state
struct string dc; /* logical datacenter */
struct array tokens; /* DHT tokens this peer owns */
bool is_local; /* is this peer the current running node? */
unsigned is_seed:1; /* seed? */

};

struct dyn_ring {
struct array ring_nodes; /* array of ring_nodes currently known in the cluster */
struct array *ring_nodes; /* array of ring_nodes currently known in the cluster */
struct server_pool *owner; /* owner pool */
};

rstatus_t dyn_ring_init(struct array *conf_seeds, struct server_pool *sp);

rstatus_t dyn_gos_run(struct context *ctx);
#endif
49 changes: 16 additions & 33 deletions src/nc_conf.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,10 @@ static struct command conf_commands[] = {
conf_set_tokens,
offsetof(struct conf_pool, tokens) },

{ string("gos_interval"),
conf_set_num,
offsetof(struct conf_pool, gos_interval) },

null_command
};

Expand Down Expand Up @@ -256,38 +260,6 @@ conf_seed_each_transform(void *elem, void *data)
return NC_OK;
}

rstatus_t
conf_seed_ring_each_transform(void *elem, void *data)
{
struct conf_server *cseed = elem;
struct array *nodes = data;

ASSERT(cseed->valid);
struct ring_node *node = array_push(nodes);
ASSERT(node != null);

node->owner = NULL;
node->pname = cseed->pname;
node->name = cseed->name;
node->port = (uint16_t)cseed->port;
node->dc = cseed->dc;

//need to check if this is local, maybe???
node->is_local = false;
//TODO-jeb need to copy over tokens, not sure if this is good enough
node->tokens = cseed->tokens;

node->family = cseed->info.family;
node->addrlen = cseed->info.addrlen;
node->addr = (struct sockaddr *)&cseed->info.addr;

node->ns_conn_q = 0;
TAILQ_INIT(&node->s_conn_q);
node->is_seed = 1;

return NC_OK;
}


static rstatus_t
conf_pool_init(struct conf_pool *cp, struct string *name)
Expand Down Expand Up @@ -334,6 +306,8 @@ conf_pool_init(struct conf_pool *cp, struct string *name)
cp->dyn_port = CONF_UNSET_NUM;
cp->dyn_connections = CONF_UNSET_NUM;

cp->gos_interval = CONF_UNSET_NUM;

array_null(&cp->server);
array_null(&cp->dyn_seeds);

Expand Down Expand Up @@ -472,7 +446,11 @@ conf_pool_each_transform(void *elem, void *data)
return status;
}

status = dyn_ring_init(&cp->dyn_seeds, sp);
/* gossip */
sp->g_interval = cp->gos_interval;

status = dyn_ring_init(&sp->peers, sp);

if (status != NC_OK) {
return status;
}
Expand Down Expand Up @@ -552,6 +530,7 @@ conf_dump(struct conf *cf)
log_debug(LOG_VVERB, " dyn_write_timeout: %d", cp->dyn_write_timeout);
log_debug(LOG_VVERB, " dyn_connections: %d", cp->dyn_connections);
log_debug(LOG_VVERB, " datacenter: %.*s", cp->dc.len, cp->dc.data);
log_debug(LOG_VVERB, " gos_interval: %d", cp->gos_interval);
}
}

Expand Down Expand Up @@ -1467,6 +1446,10 @@ conf_validate_pool(struct conf *cf, struct conf_pool *cp)
return NC_ERROR;
}

if (cp->gos_interval == CONF_UNSET_NUM) {
cp->gos_interval = CONF_DEFAULT_GOS_INTERVAL;
}

status = conf_validate_server(cf, cp);
if (status != NC_OK) {
return status;
Expand Down
5 changes: 3 additions & 2 deletions src/nc_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
#define CONF_DEFAULT_DYN_WRITE_TIMEOUT 30000
#define CONF_DEFAULT_DYN_CONNECTIONS 10
#define CONF_DEFAULT_VNODE_TOKENS 8

#define CONF_DEFAULT_GOS_INTERVAL 10000

struct conf_listen {
struct string pname; /* listen: as "name:port" */
Expand Down Expand Up @@ -107,8 +107,10 @@ struct conf_pool {
int dyn_connections; /* dyn connections */
struct string dc; /* this node's logical dc */
struct array tokens; /* this node's token */
int gos_interval; /* wake up interval in ms */
};


struct conf {
char *fname; /* file name (ref in argv[]) */
FILE *fh; /* file handle */
Expand Down Expand Up @@ -150,7 +152,6 @@ rstatus_t conf_server_each_transform(void *elem, void *data);
rstatus_t conf_pool_each_transform(void *elem, void *data);

rstatus_t conf_seed_each_transform(void *elem, void *data);
rstatus_t conf_seed_ring_each_transform(void *elem, void *data);

struct conf *conf_create(char *filename);
void conf_destroy(struct conf *cf);
Expand Down
5 changes: 4 additions & 1 deletion src/nc_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ struct server_pool {
struct array peers;
struct conn *d_conn; /* dnode connection (listener) */
struct string d_addrstr; /* pool address (ref in conf_pool) */
struct dyn_ring ring; /* ring info (shared with ring/gossip) */
uint16_t d_port; /* port */
int d_family; /* socket family */
socklen_t d_addrlen; /* socket length */
Expand All @@ -143,6 +142,10 @@ struct server_pool {
uint32_t d_connections; /* maximum # dyn connections */
struct string dc; /* the datacenter for this node */
struct array tokens; /* the DHT tokens for this server */
/* for gossiping */
struct dyn_ring ring; /* ring info (shared with ring/gossip) */
int g_interval; /* gossip interval */

};

void server_ref(struct conn *conn, void *owner);
Expand Down

0 comments on commit 30062fa

Please sign in to comment.