summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Rettberg2018-04-12 23:29:28 +0200
committerSimon Rettberg2018-04-12 23:29:28 +0200
commit26d356fa2c253affac69543298accca6406045ca (patch)
tree306594db4d3f65b101f469ca9ad4b0d8a1210d42
parent[SERVER] Mark spammy replication messages as DEBUG2 instead of 1 (diff)
downloaddnbd3-26d356fa2c253affac69543298accca6406045ca.tar.gz
dnbd3-26d356fa2c253affac69543298accca6406045ca.tar.xz
dnbd3-26d356fa2c253affac69543298accca6406045ca.zip
[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.
-rw-r--r--conf/server.conf2
-rw-r--r--src/server/globals.c7
-rw-r--r--src/server/globals.h5
-rw-r--r--src/server/uplink.c9
4 files changed, 18 insertions, 5 deletions
diff --git a/conf/server.conf b/conf/server.conf
index a33a84e..2f43247 100644
--- a/conf/server.conf
+++ b/conf/server.conf
@@ -11,6 +11,8 @@ clientPenalty=0
isProxy=true
; if proxy is true and an image is incomplete, should idle bandwidth be used to replicate missing blocks?
backgroundReplication=true
+; minimum amount of connected clients for background replication to kick in
+bgrMinClients=0
; if isProxy==true and another proxy requests and image that we don't have, should we ask our alt-servers for it?
lookupMissingForProxy=true
; create sparse files instead of preallocating; ignored if backgroundReplication=true -- only recommended if cache space is small
diff --git a/src/server/globals.c b/src/server/globals.c
index a59974f..932b3d5 100644
--- a/src/server/globals.c
+++ b/src/server/globals.c
@@ -17,6 +17,7 @@ int _serverPenalty = 0;
int _clientPenalty = 0;
bool _isProxy = false;
bool _backgroundReplication = true;
+int _bgrMinClients = 0;
bool _lookupMissingForProxy = true;
bool _sparseFiles = false;
bool _removeMissingImages = true;
@@ -55,6 +56,7 @@ static int ini_handler(void *custom UNUSED, const char* section, const char* key
SAVE_TO_VAR_BOOL( dnbd3, isProxy );
SAVE_TO_VAR_BOOL( dnbd3, proxyPrivateOnly );
SAVE_TO_VAR_BOOL( dnbd3, backgroundReplication );
+ SAVE_TO_VAR_INT( dnbd3, bgrMinClients );
SAVE_TO_VAR_BOOL( dnbd3, lookupMissingForProxy );
SAVE_TO_VAR_BOOL( dnbd3, sparseFiles );
SAVE_TO_VAR_BOOL( dnbd3, removeMissingImages );
@@ -150,8 +152,8 @@ void globals_loadConfig()
}
}
}
- if ( _backgroundReplication && _sparseFiles ) {
- logadd( LOG_WARNING, "Ignoring 'sparseFiles=true' since backgroundReplication is set to true" );
+ if ( _backgroundReplication && _sparseFiles && _bgrMinClients < 5 ) {
+ logadd( LOG_WARNING, "Ignoring 'sparseFiles=true' since backgroundReplication is set to true and bgrMinClients is too low" );
_sparseFiles = false;
}
// Dump config as interpreted
@@ -264,6 +266,7 @@ size_t globals_dumpConfig(char *buffer, size_t size)
PINT(clientPenalty);
PBOOL(isProxy);
PBOOL(backgroundReplication);
+ PINT(bgrMinClients);
PBOOL(lookupMissingForProxy);
PBOOL(sparseFiles);
PBOOL(removeMissingImages);
diff --git a/src/server/globals.h b/src/server/globals.h
index d43878f..2e39cb8 100644
--- a/src/server/globals.h
+++ b/src/server/globals.h
@@ -207,6 +207,11 @@ extern bool _closeUnusedFd;
extern bool _backgroundReplication;
/**
+ * Minimum connected clients for background replication to kick in
+ */
+extern int _bgrMinClients;
+
+/**
* (In proxy mode): If connecting client is a proxy, and the requested image
* is not known locally, should we ask our known alt servers for it?
* Otherwise the request is rejected.
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;
}