wait on DB resize whilst client(s) are being read

This catches a missed case of the trusted thread (i.e. downstream
client) reading.
This commit is contained in:
Jethro Grassie 2020-09-29 02:55:57 -04:00
parent ff323609b9
commit 08fa5c12fb
No known key found for this signature in database
GPG Key ID: DE8ED755616565BB
1 changed files with 7 additions and 0 deletions

View File

@ -470,6 +470,9 @@ database_resize(void)
log_warn("Cannot cannot acquire lock");
return rc;
}
pthread_mutex_lock(&mutex_clients);
while (clients_reading)
pthread_cond_wait(&cond_clients, &mutex_clients);
if ((rc = mdb_env_set_mapsize(env, DB_INIT_SIZE)) != 0)
{
err = mdb_strerror(rc);
@ -492,6 +495,9 @@ database_resize(void)
log_warn("Cannot cannot acquire lock");
return rc;
}
pthread_mutex_lock(&mutex_clients);
while (clients_reading)
pthread_cond_wait(&cond_clients, &mutex_clients);
if ((rc = mdb_env_set_mapsize(env, ns)) != 0)
{
err = mdb_strerror(rc);
@ -503,6 +509,7 @@ database_resize(void)
}
return 0;
unlock:
pthread_mutex_unlock(&mutex_clients);
pthread_rwlock_unlock(&rwlock_tx);
return rc;
}