From 26d356fa2c253affac69543298accca6406045ca Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Thu, 12 Apr 2018 23:29:28 +0200 Subject: [SERVER] Add bgrMinClients: Thresold to control when BGR starts Background replication will not kick in if there aren't at least that many clients connected. --- src/server/uplink.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'src/server/uplink.c') diff --git a/src/server/uplink.c b/src/server/uplink.c index 2cf8b7d..debd091 100644 --- a/src/server/uplink.c +++ b/src/server/uplink.c @@ -375,7 +375,10 @@ static void* uplink_mainloop(void *data) declare_now; if ( link->fd != -1 && link->replicationHandle == 0 && timing_reached( &nextKeepalive, &now ) ) { timing_set( &nextKeepalive, &now, 20 ); - if ( !uplink_sendKeepalive( link->fd ) ) { + if ( uplink_sendKeepalive( link->fd ) ) { + // Re-trigger periodically, in case it requires a minimum user count + uplink_sendReplicationRequest( link ); + } else { const int fd = link->fd; link->fd = -1; close( fd ); @@ -514,8 +517,8 @@ static void uplink_sendReplicationRequest(dnbd3_connection_t *link) dnbd3_image_t * const image = link->image; if ( image->realFilesize < DNBD3_BLOCK_SIZE ) return; spin_lock( &image->lock ); - if ( image == NULL || image->cache_map == NULL || link->replicationHandle != 0 ) { - // No cache map (=image complete), or replication pending, do nothing + if ( image == NULL || image->cache_map == NULL || link->replicationHandle != 0 || image->users < _bgrMinClients ) { + // No cache map (=image complete), or replication pending, or not enough users, do nothing spin_unlock( &image->lock ); return; } -- cgit v1.2.3-55-g7522