Skip to content

Commit 4625554

Browse files
committed
INTERNAL: Remove lock_arcus that are not in necessary #236
1 parent 83073f1 commit 4625554

File tree

2 files changed

+122
-0
lines changed

2 files changed

+122
-0
lines changed

libmemcached/arcus.cc

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ static pthread_mutex_t azk_mtx = PTHREAD_MUTEX_INITIALIZER;
7474
static pthread_cond_t azk_cond = PTHREAD_COND_INITIALIZER;
7575
static int azk_count;
7676

77+
#ifdef REMOVE_LOCK_ARCUS
78+
pthread_mutex_t lock_update_serverlist = PTHREAD_MUTEX_INITIALIZER;
79+
#endif
7780
pthread_mutex_t lock_arcus = PTHREAD_MUTEX_INITIALIZER;
7881
pthread_cond_t cond_arcus = PTHREAD_COND_INITIALIZER;
7982

@@ -104,7 +107,10 @@ static inline arcus_return_t do_arcus_init(memcached_st *mc,
104107
memcached_behavior_set(mc, MEMCACHED_BEHAVIOR_DISTRIBUTION, MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA_SPY);
105108
memcached_behavior_set_key_hash(mc, MEMCACHED_HASH_MD5);
106109

110+
#ifdef REMOVE_LOCK_ARCUS
111+
#else
107112
pthread_mutex_lock(&lock_arcus);
113+
#endif
108114
do {
109115
arcus= static_cast<arcus_st *>(memcached_get_server_manager(mc));
110116
if (arcus) {
@@ -155,7 +161,10 @@ static inline arcus_return_t do_arcus_init(memcached_st *mc,
155161
/* Set the Arcus to memcached as a server manager. */
156162
memcached_set_server_manager(mc, (void *)arcus);
157163
} while(0);
164+
#ifdef REMOVE_LOCK_ARCUS
165+
#else
158166
pthread_mutex_unlock(&lock_arcus);
167+
#endif
159168

160169
return rc;
161170
}
@@ -310,15 +319,21 @@ arcus_return_t arcus_close(memcached_st *mc)
310319
return rc;
311320
}
312321

322+
#ifdef REMOVE_LOCK_ARCUS
323+
#else
313324
pthread_mutex_lock(&lock_arcus);
325+
#endif
314326
arcus= static_cast<arcus_st *>(memcached_get_server_manager(mc));
315327
if (arcus) {
316328
arcus->pool= NULL;
317329
free(arcus);
318330
arcus= NULL;
319331
}
320332
memcached_set_server_manager(mc, NULL);
333+
#ifdef REMOVE_LOCK_ARCUS
334+
#else
321335
pthread_mutex_unlock(&lock_arcus);
336+
#endif
322337

323338
return ARCUS_SUCCESS;
324339
}
@@ -613,7 +628,10 @@ static inline arcus_return_t do_arcus_zk_connect(memcached_st *mc)
613628

614629
inc_count(1);
615630

631+
#ifdef REMOVE_LOCK_ARCUS
632+
#else
616633
pthread_mutex_lock(&lock_arcus);
634+
#endif
617635
do {
618636
arcus= static_cast<arcus_st *>(memcached_get_server_manager(mc));
619637
if (not arcus) {
@@ -626,20 +644,29 @@ static inline arcus_return_t do_arcus_zk_connect(memcached_st *mc)
626644

627645
ZOO_LOG_WARN(("Initiating zookeeper client"));
628646

647+
#ifdef REMOVE_LOCK_ARCUS
648+
pthread_mutex_lock(&lock_arcus);
649+
#endif
629650
/* Connect to ZooKeeper ensemble. */
630651
arcus->zk.handle= zookeeper_init(arcus->zk.ensemble_list,
631652
do_arcus_zk_watcher_global,
632653
arcus->zk.session_timeout,
633654
&(arcus->zk.myid),
634655
(void *)mc,
635656
ZOO_NO_FLAGS);
657+
#ifdef REMOVE_LOCK_ARCUS
658+
pthread_mutex_unlock(&lock_arcus);
659+
#endif
636660
if (not arcus->zk.handle) {
637661
ZOO_LOG_ERROR(("zookeeper_init() failed, reason=%s, zookeeper=%s",
638662
strerror(errno), arcus->zk.ensemble_list));
639663
rc= ARCUS_ERROR; break;
640664
}
641665
} while(0);
666+
#ifdef REMOVE_LOCK_ARCUS
667+
#else
642668
pthread_mutex_unlock(&lock_arcus);
669+
#endif
643670

644671
if (rc != ARCUS_SUCCESS) {
645672
return ARCUS_ERROR;
@@ -655,28 +682,46 @@ static inline arcus_return_t do_arcus_zk_connect(memcached_st *mc)
655682
rc= ARCUS_ERROR; break;
656683
}
657684

685+
#ifdef REMOVE_LOCK_ARCUS
686+
#else
658687
pthread_mutex_lock(&lock_arcus);
688+
#endif
659689
if (arcus->zk.conn_result != ARCUS_SUCCESS) {
660690
ZOO_LOG_ERROR(("ZooKeeper connection failed, result=%d", arcus->zk.conn_result));
691+
#ifdef REMOVE_LOCK_ARCUS
692+
#else
661693
pthread_mutex_unlock(&lock_arcus);
694+
#endif
662695
rc= ARCUS_ERROR; break;
663696
}
664697
if (do_arcus_cluster_validation_check(mc, arcus) < 0) {
698+
#ifdef REMOVE_LOCK_ARCUS
699+
#else
665700
pthread_mutex_unlock(&lock_arcus);
701+
#endif
666702
rc= ARCUS_ERROR; break;
667703
}
704+
#ifdef REMOVE_LOCK_ARCUS
705+
#else
668706
pthread_mutex_unlock(&lock_arcus);
707+
#endif
669708

670709
if (do_add_client_info(arcus) < 0) {
671710
rc= ARCUS_ERROR; break;
672711
}
673712
} while(0);
674713

675714
if (rc != ARCUS_SUCCESS) {
715+
#ifdef REMOVE_LOCK_ARCUS
716+
#else
676717
pthread_mutex_lock(&lock_arcus);
718+
#endif
677719
zookeeper_close(arcus->zk.handle);
678720
arcus->zk.handle= NULL;
721+
#ifdef REMOVE_LOCK_ARCUS
722+
#else
679723
pthread_mutex_unlock(&lock_arcus);
724+
#endif
680725
}
681726
return rc;
682727
}
@@ -691,15 +736,24 @@ static inline arcus_return_t do_arcus_zk_close(memcached_st *mc)
691736

692737
clear_count();
693738

739+
#ifdef REMOVE_LOCK_ARCUS
740+
#else
694741
pthread_mutex_lock(&lock_arcus);
742+
#endif
695743
do {
696744
arcus= static_cast<arcus_st *>(memcached_get_server_manager(mc));
697745
if (not arcus) {
698746
rc= ARCUS_ERROR; break;
699747
}
700748

749+
#ifdef REMOVE_LOCK_ARCUS
750+
pthread_mutex_lock(&lock_arcus);
751+
#endif
701752
/* Delete the (expired) session. */
702753
arcus->zk.myid.client_id= 0;
754+
#ifdef REMOVE_LOCK_ARCUS
755+
pthread_mutex_unlock(&lock_arcus);
756+
#endif
703757

704758
/* Clear connect result */
705759
arcus->zk.conn_result= ARCUS_SUCCESS;
@@ -716,7 +770,10 @@ static inline arcus_return_t do_arcus_zk_close(memcached_st *mc)
716770
}
717771
}
718772
} while(0);
773+
#ifdef REMOVE_LOCK_ARCUS
774+
#else
719775
pthread_mutex_unlock(&lock_arcus);
776+
#endif
720777

721778
return rc;
722779
}
@@ -771,9 +828,17 @@ void arcus_server_check_for_update(memcached_st *ptr)
771828
#endif
772829
{
773830
/* master's cache list was changed, update member's cache list */
831+
#ifdef REMOVE_LOCK_ARCUS
832+
pthread_mutex_lock(&lock_update_serverlist);
833+
#else
774834
pthread_mutex_lock(&lock_arcus);
835+
#endif
775836
(void)memcached_pool_update_member(arcus->pool, ptr);
837+
#ifdef REMOVE_LOCK_ARCUS
838+
pthread_mutex_unlock(&lock_update_serverlist);
839+
#else
776840
pthread_mutex_unlock(&lock_arcus);
841+
#endif
777842
}
778843
}
779844
}
@@ -947,9 +1012,17 @@ static inline void do_arcus_zk_update_cachelist_by_string(memcached_st *mc,
9471012
}
9481013
}
9491014

1015+
#ifdef REMOVE_LOCK_ARCUS
1016+
pthread_mutex_lock(&lock_update_serverlist);
1017+
#else
9501018
pthread_mutex_lock(&lock_arcus);
1019+
#endif
9511020
do_arcus_update_cachelist(mc, serverinfo, servercount);
1021+
#ifdef REMOVE_LOCK_ARCUS
1022+
pthread_mutex_unlock(&lock_update_serverlist);
1023+
#else
9521024
pthread_mutex_unlock(&lock_arcus);
1025+
#endif
9531026

9541027
libmemcached_free(mc, serverinfo);
9551028
}
@@ -1035,7 +1108,10 @@ static inline void do_arcus_zk_update_cachelist(memcached_st *mc,
10351108
{
10361109
arcus_st *arcus;
10371110

1111+
#ifdef REMOVE_LOCK_ARCUS
1112+
#else
10381113
pthread_mutex_lock(&lock_arcus);
1114+
#endif
10391115
do {
10401116
arcus= static_cast<arcus_st *>(memcached_get_server_manager(mc));
10411117
if (not arcus) {
@@ -1062,7 +1138,10 @@ static inline void do_arcus_zk_update_cachelist(memcached_st *mc,
10621138
libmemcached_free(mc, serverinfo);
10631139
}
10641140
} while(0);
1141+
#ifdef REMOVE_LOCK_ARCUS
1142+
#else
10651143
pthread_mutex_unlock(&lock_arcus);
1144+
#endif
10661145
}
10671146

10681147
static inline void do_arcus_zk_watch_and_update_cachelist(memcached_st *mc,
@@ -1114,9 +1193,15 @@ static inline void do_arcus_zk_watcher_cachelist(zhandle_t *zh __attribute__((un
11141193
ZOO_LOG_INFO(("ZOO_CHILD_EVENT from ZK cache list"));
11151194

11161195
memcached_st *mc= static_cast<memcached_st *>(ctx_mc);
1196+
#ifdef REMOVE_LOCK_ARCUS
1197+
#else
11171198
pthread_mutex_lock(&lock_arcus);
1199+
#endif
11181200
arcus_st *arcus= static_cast<arcus_st *>(memcached_get_server_manager(mc));
1201+
#ifdef REMOVE_LOCK_ARCUS
1202+
#else
11191203
pthread_mutex_unlock(&lock_arcus);
1204+
#endif
11201205
if (not arcus || not arcus->zk.handle) {
11211206
ZOO_LOG_ERROR(("arcus is null"));
11221207
return;
@@ -1147,11 +1232,17 @@ static inline void do_arcus_zk_watcher_global(zhandle_t *zh,
11471232
return;
11481233
}
11491234

1235+
#ifdef REMOVE_LOCK_ARCUS
1236+
#else
11501237
pthread_mutex_lock(&lock_arcus);
1238+
#endif
11511239
arcus= static_cast<arcus_st *>(memcached_get_server_manager(mc));
11521240
if (not arcus || not arcus->zk.handle) {
11531241
ZOO_LOG_ERROR(("arcus is null"));
1242+
#ifdef REMOVE_LOCK_ARCUS
1243+
#else
11541244
pthread_mutex_unlock(&lock_arcus);
1245+
#endif
11551246
return;
11561247
}
11571248

@@ -1160,6 +1251,9 @@ static inline void do_arcus_zk_watcher_global(zhandle_t *zh,
11601251
ZOO_LOG_WARN(("SESSION_STATE=CONNECTED, to %s", arcus->zk.ensemble_list));
11611252

11621253
const clientid_t *id= zoo_client_id(zh);
1254+
#ifdef REMOVE_LOCK_ARCUS
1255+
pthread_mutex_lock(&lock_arcus);
1256+
#endif
11631257
if (arcus->zk.myid.client_id == 0 or arcus->zk.myid.client_id != id->client_id) {
11641258
ZOO_LOG_DEBUG(("Previous sessionid : 0x%llx", (long long) arcus->zk.myid.client_id));
11651259
arcus->zk.myid= *id;
@@ -1172,12 +1266,18 @@ static inline void do_arcus_zk_watcher_global(zhandle_t *zh,
11721266
else if (state == ZOO_CONNECTING_STATE or state == ZOO_ASSOCIATING_STATE)
11731267
{
11741268
ZOO_LOG_WARN(("SESSION_STATE=CONNECTING, to %s", arcus->zk.ensemble_list));
1269+
#ifdef REMOVE_LOCK_ARCUS
1270+
#else
11751271
pthread_mutex_unlock(&lock_arcus);
1272+
#endif
11761273
}
11771274
else if (state == ZOO_AUTH_FAILED_STATE)
11781275
{
11791276
arcus->zk.conn_result= ARCUS_AUTH_FAILED;
1277+
#ifdef REMOVE_LOCK_ARCUS
1278+
#else
11801279
pthread_mutex_unlock(&lock_arcus);
1280+
#endif
11811281
if (arcus->zk_mgr.running) {
11821282
ZOO_LOG_WARN(("SESSION_STATE=AUTH_FAILED, create a new client after closing failed one"));
11831283
pthread_mutex_lock(&arcus->zk_mgr.lock);
@@ -1192,7 +1292,10 @@ static inline void do_arcus_zk_watcher_global(zhandle_t *zh,
11921292
else if (state == ZOO_EXPIRED_SESSION_STATE)
11931293
{
11941294
ZOO_LOG_WARN(("SESSION_STATE=EXPIRED_SESSION, create a new client after closing expired one"));
1295+
#ifdef REMOVE_LOCK_ARCUS
1296+
#else
11951297
pthread_mutex_unlock(&lock_arcus);
1298+
#endif
11961299
if (arcus->zk_mgr.running) {
11971300
pthread_mutex_lock(&arcus->zk_mgr.lock);
11981301
arcus->zk_mgr.request.reconnect_process= true;
@@ -1211,7 +1314,10 @@ static inline arcus_return_t do_arcus_zk_manager_start(memcached_st *mc)
12111314
arcus_return_t rc= ARCUS_SUCCESS;
12121315

12131316
/* Start arcus zk manager thread */
1317+
#ifdef REMOVE_LOCK_ARCUS
1318+
#else
12141319
pthread_mutex_lock(&lock_arcus);
1320+
#endif
12151321
do {
12161322
arcus= static_cast<arcus_st *>(memcached_get_server_manager(mc));
12171323
if (not arcus || not arcus->zk.handle) {
@@ -1235,15 +1341,21 @@ static inline arcus_return_t do_arcus_zk_manager_start(memcached_st *mc)
12351341
do_arcus_zk_manager_wakeup(mc, true);
12361342
pthread_mutex_unlock(&arcus->zk_mgr.lock);
12371343
} while(0);
1344+
#ifdef REMOVE_LOCK_ARCUS
1345+
#else
12381346
pthread_mutex_unlock(&lock_arcus);
1347+
#endif
12391348

12401349
if (rc != ARCUS_SUCCESS) {
12411350
return rc;
12421351
}
12431352

12441353
ZOO_LOG_WARN(("Waiting for the cache server list..."));
12451354

1355+
#ifdef REMOVE_LOCK_ARCUS
1356+
#else
12461357
pthread_mutex_lock(&lock_arcus);
1358+
#endif
12471359
arcus= static_cast<arcus_st *>(memcached_get_server_manager(mc));
12481360
if (arcus && arcus->zk.is_initializing) {
12491361
struct timeval now;
@@ -1259,7 +1371,10 @@ static inline arcus_return_t do_arcus_zk_manager_start(memcached_st *mc)
12591371
rc= ARCUS_ERROR;
12601372
}
12611373
}
1374+
#ifdef REMOVE_LOCK_ARCUS
1375+
#else
12621376
pthread_mutex_unlock(&lock_arcus);
1377+
#endif
12631378

12641379
if (rc == ARCUS_SUCCESS) {
12651380
ZOO_LOG_WARN(("Done"));
@@ -1271,9 +1386,15 @@ static inline void do_arcus_zk_manager_stop(memcached_st *mc)
12711386
{
12721387
arcus_st *arcus;
12731388

1389+
#ifdef REMOVE_LOCK_ARCUS
1390+
#else
12741391
pthread_mutex_lock(&lock_arcus);
1392+
#endif
12751393
arcus= static_cast<arcus_st *>(memcached_get_server_manager(mc));
1394+
#ifdef REMOVE_LOCK_ARCUS
1395+
#else
12761396
pthread_mutex_unlock(&lock_arcus);
1397+
#endif
12771398
if (arcus && arcus->zk_mgr.running) {
12781399
ZOO_LOG_WARN(("Wait for the arcus zookeeper manager to stop"));
12791400
arcus->zk_mgr.reqstop= true;

libmemcached/constants.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
#define POOL_UPDATE_SERVERLIST 1
6767
#define POOL_MORE_CONCURRENCY 1
6868
#define KETAMA_HASH_COLLSION 1
69+
#define REMOVE_LOCK_ARCUS 1
6970

7071
/* Public defines */
7172
#define MEMCACHED_DEFAULT_PORT 11211

0 commit comments

Comments
 (0)