Skip to content

Commit

Permalink
FIX: Add proxy_lock_count for multiple proxy in a process
Browse files Browse the repository at this point in the history
  • Loading branch information
namsic committed Aug 30, 2024
1 parent 44f8679 commit 77877c7
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion libmemcached/arcus.cc
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ static pthread_mutex_t azk_mtx = PTHREAD_MUTEX_INITIALIZER;
static pthread_cond_t azk_cond = PTHREAD_COND_INITIALIZER;
static int azk_count;

/* When using multiple arcus_proxy, ensure that they use different locks name */
static pthread_mutex_t proxy_lock_mtx = PTHREAD_MUTEX_INITIALIZER;
static int proxy_lock_count = 0;

pthread_mutex_t lock_arcus = PTHREAD_MUTEX_INITIALIZER;
pthread_cond_t cond_arcus = PTHREAD_COND_INITIALIZER;

Expand Down Expand Up @@ -223,15 +227,18 @@ static inline arcus_return_t do_arcus_proxy_create(memcached_st *mc,
arcus->proxy.data->mutex.locked = 0;
arcus->proxy.data->mutex.fname = NULL;

pthread_mutex_lock(&proxy_lock_mtx);
char ap_lock_fname[64];
snprintf(ap_lock_fname, 64, ".arcus_proxy_lock.%d", getpid());
snprintf(ap_lock_fname, 64, ".arcus_proxy_lock.%d.%d", getpid(), ++proxy_lock_count);

if (proc_mutex_create(&arcus->proxy.data->mutex, ap_lock_fname) != 0) {
ZOO_LOG_ERROR(("Cannot create the proxy lock file. You might have to"
" delete the lock file manually. file=%s error=%s(%d)",
ap_lock_fname, strerror(errno), errno));
pthread_mutex_unlock(&proxy_lock_mtx);
return ARCUS_ERROR;
}
pthread_mutex_unlock(&proxy_lock_mtx);

return ARCUS_SUCCESS;
}
Expand Down

0 comments on commit 77877c7

Please sign in to comment.