refactored clustering

This commit is contained in:
roberto@mrspurr
2011-06-16 07:08:56 +02:00
parent 984df3bcdf
commit 88cd033ca6
4 changed files with 15 additions and 65 deletions
+3
View File
@@ -110,7 +110,10 @@ void manage_cluster_announce(char *key, uint16_t keylen, char *val, uint16_t val
char *tmpstr;
struct uwsgi_cluster_node *ucn = (struct uwsgi_cluster_node *) data;
#ifdef UWSGI_DEBUG
uwsgi_log("%.*s = %.*s\n", keylen, key, vallen, val);
#endif
if (!uwsgi_strncmp("hostname", 8, key, keylen)) {
strncpy(ucn->nodename, val, UMIN(vallen, 255));
+5 -1
View File
@@ -825,7 +825,9 @@ int uwsgi_get_dgram(int fd, struct wsgi_request *wsgi_req) {
return -1;
}
uwsgi_log("recevied request from %s\n", inet_ntoa(sin.sin_addr));
#ifdef UWSGI_DEBUG
uwsgi_log("received request from %s\n", inet_ntoa(sin.sin_addr));
#endif
if (rlen < 4) {
uwsgi_log("invalid uwsgi packet\n");
@@ -849,7 +851,9 @@ int uwsgi_get_dgram(int fd, struct wsgi_request *wsgi_req) {
wsgi_req->buffer = buffer+4;
#ifdef UWSGI_DEBUG
uwsgi_log("request received %d %d\n", wsgi_req->uh.modifier1, wsgi_req->uh.modifier2);
#endif
return 0;
+7 -63
View File
@@ -3141,76 +3141,15 @@ void manage_opt(int i, char *optarg) {
}
void uwsgi_cluster_simple_add_node(char *nodename, int workers, int type) {
int i;
struct uwsgi_cluster_node *ucn;
char *tcp_port;
if (strlen(nodename) > 100) {
uwsgi_log("invalid cluster node name %s\n", nodename);
return;
}
tcp_port = strchr(nodename, ':');
if (tcp_port == NULL) {
fprintf(stdout, "invalid cluster node name %s\n", nodename);
return;
}
// first check for already present node
for (i = 0; i < MAX_CLUSTER_NODES; i++) {
ucn = &uwsgi.shared->nodes[i];
if (ucn->name[0] != 0) {
if (!strcmp(ucn->name, nodename)) {
ucn->status = UWSGI_NODE_OK;
ucn->last_seen = time(NULL);
return;
}
}
}
for (i = 0; i < MAX_CLUSTER_NODES; i++) {
ucn = &uwsgi.shared->nodes[i];
if (ucn->name[0] == 0) {
memcpy(ucn->name, nodename, strlen(nodename) + 1);
ucn->workers = workers;
ucn->ucn_addr.sin_family = AF_INET;
ucn->ucn_addr.sin_port = htons(atoi(tcp_port + 1));
tcp_port[0] = 0;
if (nodename[0] == 0) {
ucn->ucn_addr.sin_addr.s_addr = INADDR_ANY;
}
else {
uwsgi_log("%s\n", nodename);
ucn->ucn_addr.sin_addr.s_addr = inet_addr(nodename);
}
ucn->type = type;
// here memory can be freed, as it is allocated by uwsgi_concat2n
if (type == CLUSTER_NODE_DYNAMIC) {
free(nodename);
}
else {
tcp_port[0] = ':';
}
ucn->last_seen = time(NULL);
uwsgi_log("[uWSGI cluster] added node %s\n", ucn->name);
return;
}
}
uwsgi_log("unable to add node %s\n", nodename);
}
void uwsgi_cluster_add_node(struct uwsgi_cluster_node *nucn, int type) {
int i;
struct uwsgi_cluster_node *ucn;
char *tcp_port;
#ifdef UWSGI_DEBUG
uwsgi_log("adding node\n");
#endif
tcp_port = strchr(nucn->name, ':');
if (tcp_port == NULL) {
@@ -3246,7 +3185,9 @@ void uwsgi_cluster_add_node(struct uwsgi_cluster_node *nucn, int type) {
ucn->ucn_addr.sin_addr.s_addr = INADDR_ANY;
}
else {
#ifdef UWSGI_DEBUG
uwsgi_log("%s\n", nucn->name);
#endif
ucn->ucn_addr.sin_addr.s_addr = inet_addr(nucn->name);
}
@@ -3483,7 +3424,9 @@ int uwsgi_cluster_add_me() {
free(buf);
#ifdef UWSGI_DEBUG
uwsgi_log("add_me() successfull\n");
#endif
return 0;
}
@@ -3495,6 +3438,7 @@ int uwsgi_cluster_join(char *name) {
int broadcast = 0;
if (name[0] == ':') {
fd = bind_to_udp(name, 0, 1);
broadcast = 1;
-1
View File
@@ -1516,7 +1516,6 @@ int uwsgi_enqueue_message(char *, int, uint8_t, uint8_t, char *, int
void manage_opt(int, char *);
void uwsgi_cluster_add_node(struct uwsgi_cluster_node *, int);
void uwsgi_cluster_simple_add_node(char *, int, int);
int uwsgi_ping_node(int, struct wsgi_request *);
struct http_status_codes {