@@ -74,6 +74,9 @@ static pthread_mutex_t azk_mtx = PTHREAD_MUTEX_INITIALIZER;
74
74
static pthread_cond_t azk_cond = PTHREAD_COND_INITIALIZER;
75
75
static int azk_count;
76
76
77
+ #ifdef REMOVE_LOCK_ARCUS
78
+ pthread_mutex_t lock_update_serverlist = PTHREAD_MUTEX_INITIALIZER;
79
+ #endif
77
80
pthread_mutex_t lock_arcus = PTHREAD_MUTEX_INITIALIZER;
78
81
pthread_cond_t cond_arcus = PTHREAD_COND_INITIALIZER;
79
82
@@ -104,7 +107,10 @@ static inline arcus_return_t do_arcus_init(memcached_st *mc,
104
107
memcached_behavior_set (mc, MEMCACHED_BEHAVIOR_DISTRIBUTION, MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA_SPY);
105
108
memcached_behavior_set_key_hash (mc, MEMCACHED_HASH_MD5);
106
109
110
+ #ifdef REMOVE_LOCK_ARCUS
111
+ #else
107
112
pthread_mutex_lock (&lock_arcus);
113
+ #endif
108
114
do {
109
115
arcus= static_cast <arcus_st *>(memcached_get_server_manager (mc));
110
116
if (arcus) {
@@ -155,7 +161,10 @@ static inline arcus_return_t do_arcus_init(memcached_st *mc,
155
161
/* Set the Arcus to memcached as a server manager. */
156
162
memcached_set_server_manager (mc, (void *)arcus);
157
163
} while (0 );
164
+ #ifdef REMOVE_LOCK_ARCUS
165
+ #else
158
166
pthread_mutex_unlock (&lock_arcus);
167
+ #endif
159
168
160
169
return rc;
161
170
}
@@ -310,15 +319,21 @@ arcus_return_t arcus_close(memcached_st *mc)
310
319
return rc;
311
320
}
312
321
322
+ #ifdef REMOVE_LOCK_ARCUS
323
+ #else
313
324
pthread_mutex_lock (&lock_arcus);
325
+ #endif
314
326
arcus= static_cast <arcus_st *>(memcached_get_server_manager (mc));
315
327
if (arcus) {
316
328
arcus->pool = NULL ;
317
329
free (arcus);
318
330
arcus= NULL ;
319
331
}
320
332
memcached_set_server_manager (mc, NULL );
333
+ #ifdef REMOVE_LOCK_ARCUS
334
+ #else
321
335
pthread_mutex_unlock (&lock_arcus);
336
+ #endif
322
337
323
338
return ARCUS_SUCCESS;
324
339
}
@@ -613,7 +628,10 @@ static inline arcus_return_t do_arcus_zk_connect(memcached_st *mc)
613
628
614
629
inc_count (1 );
615
630
631
+ #ifdef REMOVE_LOCK_ARCUS
632
+ #else
616
633
pthread_mutex_lock (&lock_arcus);
634
+ #endif
617
635
do {
618
636
arcus= static_cast <arcus_st *>(memcached_get_server_manager (mc));
619
637
if (not arcus) {
@@ -626,20 +644,29 @@ static inline arcus_return_t do_arcus_zk_connect(memcached_st *mc)
626
644
627
645
ZOO_LOG_WARN ((" Initiating zookeeper client" ));
628
646
647
+ #ifdef REMOVE_LOCK_ARCUS
648
+ pthread_mutex_lock (&lock_arcus);
649
+ #endif
629
650
/* Connect to ZooKeeper ensemble. */
630
651
arcus->zk .handle = zookeeper_init (arcus->zk .ensemble_list ,
631
652
do_arcus_zk_watcher_global,
632
653
arcus->zk .session_timeout ,
633
654
&(arcus->zk .myid ),
634
655
(void *)mc,
635
656
ZOO_NO_FLAGS);
657
+ #ifdef REMOVE_LOCK_ARCUS
658
+ pthread_mutex_unlock (&lock_arcus);
659
+ #endif
636
660
if (not arcus->zk .handle ) {
637
661
ZOO_LOG_ERROR ((" zookeeper_init() failed, reason=%s, zookeeper=%s" ,
638
662
strerror (errno), arcus->zk .ensemble_list ));
639
663
rc= ARCUS_ERROR; break ;
640
664
}
641
665
} while (0 );
666
+ #ifdef REMOVE_LOCK_ARCUS
667
+ #else
642
668
pthread_mutex_unlock (&lock_arcus);
669
+ #endif
643
670
644
671
if (rc != ARCUS_SUCCESS) {
645
672
return ARCUS_ERROR;
@@ -655,28 +682,46 @@ static inline arcus_return_t do_arcus_zk_connect(memcached_st *mc)
655
682
rc= ARCUS_ERROR; break ;
656
683
}
657
684
685
+ #ifdef REMOVE_LOCK_ARCUS
686
+ #else
658
687
pthread_mutex_lock (&lock_arcus);
688
+ #endif
659
689
if (arcus->zk .conn_result != ARCUS_SUCCESS) {
660
690
ZOO_LOG_ERROR ((" ZooKeeper connection failed, result=%d" , arcus->zk .conn_result ));
691
+ #ifdef REMOVE_LOCK_ARCUS
692
+ #else
661
693
pthread_mutex_unlock (&lock_arcus);
694
+ #endif
662
695
rc= ARCUS_ERROR; break ;
663
696
}
664
697
if (do_arcus_cluster_validation_check (mc, arcus) < 0 ) {
698
+ #ifdef REMOVE_LOCK_ARCUS
699
+ #else
665
700
pthread_mutex_unlock (&lock_arcus);
701
+ #endif
666
702
rc= ARCUS_ERROR; break ;
667
703
}
704
+ #ifdef REMOVE_LOCK_ARCUS
705
+ #else
668
706
pthread_mutex_unlock (&lock_arcus);
707
+ #endif
669
708
670
709
if (do_add_client_info (arcus) < 0 ) {
671
710
rc= ARCUS_ERROR; break ;
672
711
}
673
712
} while (0 );
674
713
675
714
if (rc != ARCUS_SUCCESS) {
715
+ #ifdef REMOVE_LOCK_ARCUS
716
+ #else
676
717
pthread_mutex_lock (&lock_arcus);
718
+ #endif
677
719
zookeeper_close (arcus->zk .handle );
678
720
arcus->zk .handle = NULL ;
721
+ #ifdef REMOVE_LOCK_ARCUS
722
+ #else
679
723
pthread_mutex_unlock (&lock_arcus);
724
+ #endif
680
725
}
681
726
return rc;
682
727
}
@@ -691,15 +736,24 @@ static inline arcus_return_t do_arcus_zk_close(memcached_st *mc)
691
736
692
737
clear_count ();
693
738
739
+ #ifdef REMOVE_LOCK_ARCUS
740
+ #else
694
741
pthread_mutex_lock (&lock_arcus);
742
+ #endif
695
743
do {
696
744
arcus= static_cast <arcus_st *>(memcached_get_server_manager (mc));
697
745
if (not arcus) {
698
746
rc= ARCUS_ERROR; break ;
699
747
}
700
748
749
+ #ifdef REMOVE_LOCK_ARCUS
750
+ pthread_mutex_lock (&lock_arcus);
751
+ #endif
701
752
/* Delete the (expired) session. */
702
753
arcus->zk .myid .client_id = 0 ;
754
+ #ifdef REMOVE_LOCK_ARCUS
755
+ pthread_mutex_unlock (&lock_arcus);
756
+ #endif
703
757
704
758
/* Clear connect result */
705
759
arcus->zk .conn_result = ARCUS_SUCCESS;
@@ -716,7 +770,10 @@ static inline arcus_return_t do_arcus_zk_close(memcached_st *mc)
716
770
}
717
771
}
718
772
} while (0 );
773
+ #ifdef REMOVE_LOCK_ARCUS
774
+ #else
719
775
pthread_mutex_unlock (&lock_arcus);
776
+ #endif
720
777
721
778
return rc;
722
779
}
@@ -771,9 +828,17 @@ void arcus_server_check_for_update(memcached_st *ptr)
771
828
#endif
772
829
{
773
830
/* 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
774
834
pthread_mutex_lock (&lock_arcus);
835
+ #endif
775
836
(void )memcached_pool_update_member (arcus->pool , ptr);
837
+ #ifdef REMOVE_LOCK_ARCUS
838
+ pthread_mutex_unlock (&lock_update_serverlist);
839
+ #else
776
840
pthread_mutex_unlock (&lock_arcus);
841
+ #endif
777
842
}
778
843
}
779
844
}
@@ -947,9 +1012,17 @@ static inline void do_arcus_zk_update_cachelist_by_string(memcached_st *mc,
947
1012
}
948
1013
}
949
1014
1015
+ #ifdef REMOVE_LOCK_ARCUS
1016
+ pthread_mutex_lock (&lock_update_serverlist);
1017
+ #else
950
1018
pthread_mutex_lock (&lock_arcus);
1019
+ #endif
951
1020
do_arcus_update_cachelist (mc, serverinfo, servercount);
1021
+ #ifdef REMOVE_LOCK_ARCUS
1022
+ pthread_mutex_unlock (&lock_update_serverlist);
1023
+ #else
952
1024
pthread_mutex_unlock (&lock_arcus);
1025
+ #endif
953
1026
954
1027
libmemcached_free (mc, serverinfo);
955
1028
}
@@ -1035,7 +1108,10 @@ static inline void do_arcus_zk_update_cachelist(memcached_st *mc,
1035
1108
{
1036
1109
arcus_st *arcus;
1037
1110
1111
+ #ifdef REMOVE_LOCK_ARCUS
1112
+ #else
1038
1113
pthread_mutex_lock (&lock_arcus);
1114
+ #endif
1039
1115
do {
1040
1116
arcus= static_cast <arcus_st *>(memcached_get_server_manager (mc));
1041
1117
if (not arcus) {
@@ -1062,7 +1138,10 @@ static inline void do_arcus_zk_update_cachelist(memcached_st *mc,
1062
1138
libmemcached_free (mc, serverinfo);
1063
1139
}
1064
1140
} while (0 );
1141
+ #ifdef REMOVE_LOCK_ARCUS
1142
+ #else
1065
1143
pthread_mutex_unlock (&lock_arcus);
1144
+ #endif
1066
1145
}
1067
1146
1068
1147
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
1114
1193
ZOO_LOG_INFO ((" ZOO_CHILD_EVENT from ZK cache list" ));
1115
1194
1116
1195
memcached_st *mc= static_cast <memcached_st *>(ctx_mc);
1196
+ #ifdef REMOVE_LOCK_ARCUS
1197
+ #else
1117
1198
pthread_mutex_lock (&lock_arcus);
1199
+ #endif
1118
1200
arcus_st *arcus= static_cast <arcus_st *>(memcached_get_server_manager (mc));
1201
+ #ifdef REMOVE_LOCK_ARCUS
1202
+ #else
1119
1203
pthread_mutex_unlock (&lock_arcus);
1204
+ #endif
1120
1205
if (not arcus || not arcus->zk .handle ) {
1121
1206
ZOO_LOG_ERROR ((" arcus is null" ));
1122
1207
return ;
@@ -1147,11 +1232,17 @@ static inline void do_arcus_zk_watcher_global(zhandle_t *zh,
1147
1232
return ;
1148
1233
}
1149
1234
1235
+ #ifdef REMOVE_LOCK_ARCUS
1236
+ #else
1150
1237
pthread_mutex_lock (&lock_arcus);
1238
+ #endif
1151
1239
arcus= static_cast <arcus_st *>(memcached_get_server_manager (mc));
1152
1240
if (not arcus || not arcus->zk .handle ) {
1153
1241
ZOO_LOG_ERROR ((" arcus is null" ));
1242
+ #ifdef REMOVE_LOCK_ARCUS
1243
+ #else
1154
1244
pthread_mutex_unlock (&lock_arcus);
1245
+ #endif
1155
1246
return ;
1156
1247
}
1157
1248
@@ -1160,6 +1251,9 @@ static inline void do_arcus_zk_watcher_global(zhandle_t *zh,
1160
1251
ZOO_LOG_WARN ((" SESSION_STATE=CONNECTED, to %s" , arcus->zk .ensemble_list ));
1161
1252
1162
1253
const clientid_t *id= zoo_client_id (zh);
1254
+ #ifdef REMOVE_LOCK_ARCUS
1255
+ pthread_mutex_lock (&lock_arcus);
1256
+ #endif
1163
1257
if (arcus->zk .myid .client_id == 0 or arcus->zk .myid .client_id != id->client_id ) {
1164
1258
ZOO_LOG_DEBUG ((" Previous sessionid : 0x%llx" , (long long ) arcus->zk .myid .client_id ));
1165
1259
arcus->zk .myid = *id;
@@ -1172,12 +1266,18 @@ static inline void do_arcus_zk_watcher_global(zhandle_t *zh,
1172
1266
else if (state == ZOO_CONNECTING_STATE or state == ZOO_ASSOCIATING_STATE)
1173
1267
{
1174
1268
ZOO_LOG_WARN ((" SESSION_STATE=CONNECTING, to %s" , arcus->zk .ensemble_list ));
1269
+ #ifdef REMOVE_LOCK_ARCUS
1270
+ #else
1175
1271
pthread_mutex_unlock (&lock_arcus);
1272
+ #endif
1176
1273
}
1177
1274
else if (state == ZOO_AUTH_FAILED_STATE)
1178
1275
{
1179
1276
arcus->zk .conn_result = ARCUS_AUTH_FAILED;
1277
+ #ifdef REMOVE_LOCK_ARCUS
1278
+ #else
1180
1279
pthread_mutex_unlock (&lock_arcus);
1280
+ #endif
1181
1281
if (arcus->zk_mgr .running ) {
1182
1282
ZOO_LOG_WARN ((" SESSION_STATE=AUTH_FAILED, create a new client after closing failed one" ));
1183
1283
pthread_mutex_lock (&arcus->zk_mgr .lock );
@@ -1192,7 +1292,10 @@ static inline void do_arcus_zk_watcher_global(zhandle_t *zh,
1192
1292
else if (state == ZOO_EXPIRED_SESSION_STATE)
1193
1293
{
1194
1294
ZOO_LOG_WARN ((" SESSION_STATE=EXPIRED_SESSION, create a new client after closing expired one" ));
1295
+ #ifdef REMOVE_LOCK_ARCUS
1296
+ #else
1195
1297
pthread_mutex_unlock (&lock_arcus);
1298
+ #endif
1196
1299
if (arcus->zk_mgr .running ) {
1197
1300
pthread_mutex_lock (&arcus->zk_mgr .lock );
1198
1301
arcus->zk_mgr .request .reconnect_process = true ;
@@ -1211,7 +1314,10 @@ static inline arcus_return_t do_arcus_zk_manager_start(memcached_st *mc)
1211
1314
arcus_return_t rc= ARCUS_SUCCESS;
1212
1315
1213
1316
/* Start arcus zk manager thread */
1317
+ #ifdef REMOVE_LOCK_ARCUS
1318
+ #else
1214
1319
pthread_mutex_lock (&lock_arcus);
1320
+ #endif
1215
1321
do {
1216
1322
arcus= static_cast <arcus_st *>(memcached_get_server_manager (mc));
1217
1323
if (not arcus || not arcus->zk .handle ) {
@@ -1235,15 +1341,21 @@ static inline arcus_return_t do_arcus_zk_manager_start(memcached_st *mc)
1235
1341
do_arcus_zk_manager_wakeup (mc, true );
1236
1342
pthread_mutex_unlock (&arcus->zk_mgr .lock );
1237
1343
} while (0 );
1344
+ #ifdef REMOVE_LOCK_ARCUS
1345
+ #else
1238
1346
pthread_mutex_unlock (&lock_arcus);
1347
+ #endif
1239
1348
1240
1349
if (rc != ARCUS_SUCCESS) {
1241
1350
return rc;
1242
1351
}
1243
1352
1244
1353
ZOO_LOG_WARN ((" Waiting for the cache server list..." ));
1245
1354
1355
+ #ifdef REMOVE_LOCK_ARCUS
1356
+ #else
1246
1357
pthread_mutex_lock (&lock_arcus);
1358
+ #endif
1247
1359
arcus= static_cast <arcus_st *>(memcached_get_server_manager (mc));
1248
1360
if (arcus && arcus->zk .is_initializing ) {
1249
1361
struct timeval now;
@@ -1259,7 +1371,10 @@ static inline arcus_return_t do_arcus_zk_manager_start(memcached_st *mc)
1259
1371
rc= ARCUS_ERROR;
1260
1372
}
1261
1373
}
1374
+ #ifdef REMOVE_LOCK_ARCUS
1375
+ #else
1262
1376
pthread_mutex_unlock (&lock_arcus);
1377
+ #endif
1263
1378
1264
1379
if (rc == ARCUS_SUCCESS) {
1265
1380
ZOO_LOG_WARN ((" Done" ));
@@ -1271,9 +1386,15 @@ static inline void do_arcus_zk_manager_stop(memcached_st *mc)
1271
1386
{
1272
1387
arcus_st *arcus;
1273
1388
1389
+ #ifdef REMOVE_LOCK_ARCUS
1390
+ #else
1274
1391
pthread_mutex_lock (&lock_arcus);
1392
+ #endif
1275
1393
arcus= static_cast <arcus_st *>(memcached_get_server_manager (mc));
1394
+ #ifdef REMOVE_LOCK_ARCUS
1395
+ #else
1276
1396
pthread_mutex_unlock (&lock_arcus);
1397
+ #endif
1277
1398
if (arcus && arcus->zk_mgr .running ) {
1278
1399
ZOO_LOG_WARN ((" Wait for the arcus zookeeper manager to stop" ));
1279
1400
arcus->zk_mgr .reqstop = true ;
0 commit comments