summaryrefslogtreecommitdiff
path: root/src/master.c
diff options
context:
space:
mode:
authorAndreas Baumann <mail@andreasbaumann.cc>2014-11-14 12:20:19 +0100
committerAndreas Baumann <mail@andreasbaumann.cc>2014-11-14 12:20:19 +0100
commitcda6f82b0e0035ee1176cdb5b6f2f797f897e8f0 (patch)
treec6811517a86c0ba3d8f6af54e92b62041a6af297 /src/master.c
parent0fcd6d23cb647f686c6b01c81dcc5e2b057d8948 (diff)
downloadbiruda-cda6f82b0e0035ee1176cdb5b6f2f797f897e8f0.tar.gz
biruda-cda6f82b0e0035ee1176cdb5b6f2f797f897e8f0.tar.bz2
failing to answer to a discover declare a coordinator dead in the master after some time
Diffstat (limited to 'src/master.c')
-rw-r--r--src/master.c29
1 files changed, 20 insertions, 9 deletions
diff --git a/src/master.c b/src/master.c
index 53b71b8..3cd2173 100644
--- a/src/master.c
+++ b/src/master.c
@@ -16,14 +16,18 @@ static int master_must_terminate = 0;
coordinator_t coordinator[MAX_COORDINATORS];
-static void reregister_coordinator( const char *host )
+static void recompute_coordinator_states( void )
{
- int pos;
- for( pos = 0; pos < MAX_COORDINATORS; pos++ ) {
- if( coordinator[pos].used &&
- strcmp( coordinator[pos].host, host ) == 0 ) {
- coordinator[pos].used = false;
- return;
+ time_t now;
+ time( &now );
+ for( int pos = 0; pos < MAX_COORDINATORS; pos++ ) {
+ coordinator_t *c = &coordinator[pos];
+ if( c->used ) {
+ double d = difftime( now, c->lastAlive );
+ fprintf( stderr, "%s %lld %lld %g\n", c->host, (long long)c->lastAlive, (long long)now, d );
+ if( difftime( now, c->lastAlive ) > MAX_COORDINATOR_AGE ) {
+ c->alive = false;
+ }
}
}
}
@@ -48,8 +52,11 @@ static void register_coordinator( json_object *obj )
int pos;
for( pos = 0; pos < MAX_COORDINATORS; pos++ ) {
- if( coordinator[pos].used &&
- strcmp( coordinator[pos].host, host ) == 0 ) {
+ coordinator_t *coord = &coordinator[pos];
+ if( coord->used &&
+ strcmp( coord->host, host ) == 0 ) {
+ time( &coord->lastAlive );
+ coord->alive = true;
fprintf( stderr, "master: already registered coordinator from host '%s' (%d)\n", host, pos );
return;
}
@@ -69,6 +76,8 @@ static void register_coordinator( json_object *obj )
coord->os = strdup( os );
coord->arch = strdup( arch );
coord->cpus = cpus;
+ coord->alive = true;
+ time( &coord->lastAlive );
coord->used = true;
}
@@ -116,6 +125,8 @@ NEXT_DISCOVER:
printf( "master idle: %d\n", master_must_terminate );
+ recompute_coordinator_states( );
+
char *answer = NULL;
bytes = nn_recv( master_sock, &answer, NN_MSG, 0 );
if( master_must_terminate ) continue;