slyphon-zookeeper 0.3.0-java → 0.8.0-java
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG +34 -0
- data/Rakefile +25 -5
- data/ext/c_zookeeper.rb +214 -0
- data/ext/dbg.h +18 -2
- data/ext/depend +1 -2
- data/ext/zookeeper_base.rb +73 -99
- data/ext/zookeeper_c.c +52 -41
- data/ext/zookeeper_lib.c +90 -78
- data/ext/zookeeper_lib.h +0 -1
- data/java/zookeeper_base.rb +72 -154
- data/lib/zookeeper/common/queue_with_pipe.rb +78 -0
- data/lib/zookeeper/common.rb +73 -9
- data/lib/zookeeper/constants.rb +28 -0
- data/lib/zookeeper/em_client.rb +13 -138
- data/lib/zookeeper/exceptions.rb +4 -1
- data/lib/zookeeper.rb +51 -15
- data/slyphon-zookeeper.gemspec +1 -1
- data/spec/c_zookeeper_spec.rb +50 -0
- data/spec/chrooted_connection_spec.rb +121 -0
- data/spec/em_spec.rb +0 -61
- data/spec/shared/all_success_return_values.rb +10 -0
- data/spec/shared/connection_examples.rb +1007 -0
- data/spec/spec_helper.rb +42 -19
- data/spec/zookeeper_spec.rb +8 -1033
- metadata +16 -6
data/ext/zookeeper_c.c
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
* Phillip Pearson <pp@myelin.co.nz>
|
3
3
|
* Eric Maland <eric@twitter.com>
|
4
4
|
* Brian Wickman <wickman@twitter.com>
|
5
|
+
* Jonathan D. Simms <slyphon@gmail.com>
|
5
6
|
*
|
6
7
|
* This fork is a 90% rewrite of the original. It takes a more evented
|
7
8
|
* approach to isolate the ZK state machine from the ruby interpreter via an
|
@@ -108,6 +109,7 @@ static int zkrb_dup(int orig) {
|
|
108
109
|
return fd;
|
109
110
|
}
|
110
111
|
|
112
|
+
#if 0
|
111
113
|
static VALUE create_selectable_io(zkrb_queue_t *q) {
|
112
114
|
// rb_cIO is the ruby IO class?
|
113
115
|
|
@@ -127,8 +129,11 @@ static VALUE create_selectable_io(zkrb_queue_t *q) {
|
|
127
129
|
|
128
130
|
return reader;
|
129
131
|
}
|
132
|
+
#endif
|
130
133
|
|
131
|
-
|
134
|
+
#define session_timeout_msec(self) rb_iv_get(self, "@_session_timeout_msec")
|
135
|
+
|
136
|
+
static VALUE method_zkrb_init(int argc, VALUE* argv, VALUE self) {
|
132
137
|
VALUE hostPort;
|
133
138
|
VALUE options;
|
134
139
|
|
@@ -157,6 +162,9 @@ static VALUE method_init(int argc, VALUE* argv, VALUE self) {
|
|
157
162
|
data = Data_Make_Struct(Zookeeper, struct zkrb_instance_data, 0, free_zkrb_instance_data, zk_local_ctx);
|
158
163
|
zk_local_ctx->queue = zkrb_queue_alloc();
|
159
164
|
|
165
|
+
if (zk_local_ctx->queue == NULL)
|
166
|
+
rb_raise(rb_eRuntimeError, "could not allocate zkrb queue!");
|
167
|
+
|
160
168
|
zoo_deterministic_conn_order(0);
|
161
169
|
|
162
170
|
zkrb_calling_context *ctx =
|
@@ -168,7 +176,7 @@ static VALUE method_init(int argc, VALUE* argv, VALUE self) {
|
|
168
176
|
zookeeper_init(
|
169
177
|
RSTRING_PTR(hostPort),
|
170
178
|
zkrb_state_callback,
|
171
|
-
|
179
|
+
session_timeout_msec(self),
|
172
180
|
&zk_local_ctx->myid,
|
173
181
|
ctx,
|
174
182
|
0);
|
@@ -179,10 +187,9 @@ static VALUE method_init(int argc, VALUE* argv, VALUE self) {
|
|
179
187
|
}
|
180
188
|
|
181
189
|
rb_iv_set(self, "@_data", data);
|
182
|
-
|
183
|
-
rb_iv_set(self, "@_running", Qtrue);
|
184
|
-
|
190
|
+
rb_funcall(self, rb_intern("zkc_set_running_and_notify!"), 0);
|
185
191
|
|
192
|
+
error:
|
186
193
|
return Qnil;
|
187
194
|
}
|
188
195
|
|
@@ -282,6 +289,19 @@ static VALUE method_exists(VALUE self, VALUE reqid, VALUE path, VALUE async, VAL
|
|
282
289
|
return output;
|
283
290
|
}
|
284
291
|
|
292
|
+
// this method is *only* called asynchronously
|
293
|
+
static VALUE method_sync(VALUE self, VALUE reqid, VALUE path) {
|
294
|
+
VALUE async = Qtrue;
|
295
|
+
VALUE watch = Qfalse;
|
296
|
+
int rc;
|
297
|
+
|
298
|
+
STANDARD_PREAMBLE(self, zk, reqid, path, async, watch, data_ctx, watch_ctx, call_type);
|
299
|
+
|
300
|
+
rc = zoo_async(zk->zh, RSTRING_PTR(path), zkrb_string_callback, data_ctx);
|
301
|
+
|
302
|
+
return INT2FIX(rc);
|
303
|
+
}
|
304
|
+
|
285
305
|
static VALUE method_create(VALUE self, VALUE reqid, VALUE path, VALUE data, VALUE async, VALUE acls, VALUE flags) {
|
286
306
|
VALUE watch = Qfalse;
|
287
307
|
STANDARD_PREAMBLE(self, zk, reqid, path, async, watch, data_ctx, watch_ctx, call_type);
|
@@ -477,46 +497,39 @@ static VALUE method_get_acl(VALUE self, VALUE reqid, VALUE path, VALUE async) {
|
|
477
497
|
return output;
|
478
498
|
}
|
479
499
|
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
}
|
484
|
-
|
485
|
-
static int is_closed(VALUE self) {
|
486
|
-
VALUE rval = rb_iv_get(self, "@_closed");
|
487
|
-
return RTEST(rval);
|
488
|
-
}
|
489
|
-
|
490
|
-
/* slyphon: NEED TO PROTECT THIS AGAINST SHUTDOWN */
|
500
|
+
#define is_running(self) RTEST(rb_iv_get(self, "@_running"))
|
501
|
+
#define is_closed(self) RTEST(rb_iv_get(self, "@_closed"))
|
502
|
+
#define is_shutting_down(self) RTEST(rb_iv_get(self, "@_shutting_down"))
|
491
503
|
|
492
504
|
static VALUE method_get_next_event(VALUE self, VALUE blocking) {
|
505
|
+
// dbg.h
|
506
|
+
check_debug(!is_closed(self), "we are closed, not trying to get event");
|
507
|
+
|
493
508
|
char buf[64];
|
494
509
|
FETCH_DATA_PTR(self, zk);
|
495
510
|
|
496
511
|
for (;;) {
|
497
|
-
|
498
|
-
// we use the is_running(self) method here because it allows us to have a
|
499
|
-
// ruby-land semaphore that we can also use in the java extension
|
500
|
-
//
|
501
|
-
if (is_closed(self) || !is_running(self)) {
|
502
|
-
zkrb_debug_inst(self, "is_closed(self): %d, is_running(self): %d, method_get_next_event is exiting loop", is_closed(self), is_running(self));
|
503
|
-
return Qnil; // this case for shutdown
|
504
|
-
}
|
512
|
+
check_debug(!is_closed(self), "we're closed in the middle of method_get_next_event, bailing");
|
505
513
|
|
506
514
|
zkrb_event_t *event = zkrb_dequeue(zk->queue, 1);
|
507
515
|
|
508
516
|
/* Wait for an event using rb_thread_select() on the queue's pipe */
|
509
517
|
if (event == NULL) {
|
510
518
|
if (NIL_P(blocking) || (blocking == Qfalse)) {
|
511
|
-
|
519
|
+
goto error;
|
512
520
|
}
|
513
521
|
else {
|
522
|
+
// if we're shutting down, don't enter this section, we don't want to block
|
523
|
+
check_debug(!is_shutting_down(self), "method_get_next_event, we're shutting down, don't enter blocking section");
|
524
|
+
|
514
525
|
int fd = zk->queue->pipe_read;
|
515
526
|
ssize_t bytes_read = 0;
|
516
527
|
|
517
528
|
// wait for an fd to become readable, opposite of rb_thread_fd_writable
|
518
529
|
rb_thread_wait_fd(fd);
|
519
530
|
|
531
|
+
// clear all bytes here, we'll catch all the events on subsequent calls
|
532
|
+
// (until we run out of events)
|
520
533
|
bytes_read = read(fd, buf, sizeof(buf));
|
521
534
|
|
522
535
|
if (bytes_read == -1) {
|
@@ -533,6 +546,9 @@ static VALUE method_get_next_event(VALUE self, VALUE blocking) {
|
|
533
546
|
zkrb_event_free(event);
|
534
547
|
return hash;
|
535
548
|
}
|
549
|
+
|
550
|
+
error:
|
551
|
+
return Qnil;
|
536
552
|
}
|
537
553
|
|
538
554
|
static VALUE method_has_events(VALUE self) {
|
@@ -554,15 +570,6 @@ static VALUE method_wake_event_loop_bang(VALUE self) {
|
|
554
570
|
return Qnil;
|
555
571
|
};
|
556
572
|
|
557
|
-
// static VALUE method_signal_pending_close(VALUE self) {
|
558
|
-
// FETCH_DATA_PTR(self, zk);
|
559
|
-
//
|
560
|
-
// zk->pending_close = 1;
|
561
|
-
// zkrb_signal(zk->queue);
|
562
|
-
//
|
563
|
-
// return Qnil;
|
564
|
-
// }
|
565
|
-
|
566
573
|
static VALUE method_close_handle(VALUE self) {
|
567
574
|
FETCH_DATA_PTR(self, zk);
|
568
575
|
|
@@ -597,7 +604,7 @@ static VALUE method_is_unrecoverable(VALUE self) {
|
|
597
604
|
return is_unrecoverable(zk->zh) == ZINVALIDSTATE ? Qtrue : Qfalse;
|
598
605
|
}
|
599
606
|
|
600
|
-
static VALUE
|
607
|
+
static VALUE method_zkrb_state(VALUE self) {
|
601
608
|
FETCH_DATA_PTR(self, zk);
|
602
609
|
return INT2NUM(zoo_state(zk->zh));
|
603
610
|
}
|
@@ -630,7 +637,7 @@ static VALUE method_client_id(VALUE self) {
|
|
630
637
|
return client_id_obj;
|
631
638
|
}
|
632
639
|
|
633
|
-
static VALUE
|
640
|
+
static VALUE klass_method_zkrb_set_debug_level(VALUE klass, VALUE level) {
|
634
641
|
Check_Type(level, T_FIXNUM);
|
635
642
|
ZKRBDebugging = (FIX2INT(level) == ZOO_LOG_LEVEL_DEBUG);
|
636
643
|
zoo_set_debug_level(FIX2INT(level));
|
@@ -647,7 +654,8 @@ static void zkrb_define_methods(void) {
|
|
647
654
|
#define DEFINE_CLASS_METHOD(method, args) { \
|
648
655
|
rb_define_singleton_method(Zookeeper, #method, method_ ## method, args); }
|
649
656
|
|
650
|
-
|
657
|
+
// the number after the method name should be actual arity of C function - 1
|
658
|
+
DEFINE_METHOD(zkrb_init, -1);
|
651
659
|
DEFINE_METHOD(get_children, 4);
|
652
660
|
DEFINE_METHOD(exists, 4);
|
653
661
|
DEFINE_METHOD(create, 6);
|
@@ -661,10 +669,11 @@ static void zkrb_define_methods(void) {
|
|
661
669
|
DEFINE_METHOD(deterministic_conn_order, 1);
|
662
670
|
DEFINE_METHOD(is_unrecoverable, 0);
|
663
671
|
DEFINE_METHOD(recv_timeout, 1);
|
664
|
-
DEFINE_METHOD(
|
672
|
+
DEFINE_METHOD(zkrb_state, 0);
|
673
|
+
DEFINE_METHOD(sync, 2);
|
674
|
+
|
665
675
|
// TODO
|
666
676
|
// DEFINE_METHOD(add_auth, 3);
|
667
|
-
// DEFINE_METHOD(async, 1);
|
668
677
|
|
669
678
|
// methods for the ruby-side event manager
|
670
679
|
DEFINE_METHOD(get_next_event, 1);
|
@@ -673,11 +682,11 @@ static void zkrb_define_methods(void) {
|
|
673
682
|
// Make these class methods?
|
674
683
|
DEFINE_METHOD(zerror, 1);
|
675
684
|
|
676
|
-
rb_define_singleton_method(Zookeeper, "
|
685
|
+
rb_define_singleton_method(Zookeeper, "set_zkrb_debug_level", klass_method_zkrb_set_debug_level, 1);
|
677
686
|
|
678
687
|
rb_attr(Zookeeper, rb_intern("selectable_io"), 1, 0, Qtrue);
|
679
|
-
|
680
688
|
rb_define_method(Zookeeper, "wake_event_loop!", method_wake_event_loop_bang, 0);
|
689
|
+
|
681
690
|
}
|
682
691
|
|
683
692
|
// class CZookeeper::ClientId
|
@@ -695,8 +704,10 @@ static VALUE zkrb_client_id_method_initialize(VALUE self) {
|
|
695
704
|
return Qnil;
|
696
705
|
}
|
697
706
|
|
707
|
+
|
698
708
|
void Init_zookeeper_c() {
|
699
709
|
ZKRBDebugging = 0;
|
710
|
+
|
700
711
|
/* initialize Zookeeper class */
|
701
712
|
Zookeeper = rb_define_class("CZookeeper", rb_cObject);
|
702
713
|
zkrb_define_methods();
|
data/ext/zookeeper_lib.c
CHANGED
@@ -6,6 +6,17 @@ This file contains three sets of helpers:
|
|
6
6
|
- functions for translating between Ruby and C versions of ZK datatypes
|
7
7
|
|
8
8
|
wickman@twitter.com
|
9
|
+
|
10
|
+
*********************************************************************************
|
11
|
+
*
|
12
|
+
* NOTE: be *very careful* in these functions, calling *ANY* ruby interpreter
|
13
|
+
* function when you're not in an interpreter thread can hork ruby, trigger a
|
14
|
+
* [BUG], corrupt the stack, kill your dog, knock up your daughter, etc. etc.
|
15
|
+
*
|
16
|
+
*********************************************************************************
|
17
|
+
|
18
|
+
slyphon@gmail.com
|
19
|
+
|
9
20
|
*/
|
10
21
|
|
11
22
|
#include "ruby.h"
|
@@ -23,104 +34,117 @@ wickman@twitter.com
|
|
23
34
|
|
24
35
|
int ZKRBDebugging;
|
25
36
|
|
37
|
+
// XXX(slyphon): need to check these for error, but what to do if they fail?
|
26
38
|
pthread_mutex_t zkrb_q_mutex = PTHREAD_MUTEX_INITIALIZER;
|
27
39
|
|
40
|
+
#define LOG_PTHREAD_ERR(A, M, ...) if (A) { log_err(M, ##__VA_ARGS__); errno=0; }
|
41
|
+
|
42
|
+
#define GLOBAL_MUTEX_LOCK(F) LOG_PTHREAD_ERR(pthread_mutex_lock(&zkrb_q_mutex), F)
|
43
|
+
#define GLOBAL_MUTEX_UNLOCK(F) LOG_PTHREAD_ERR(pthread_mutex_unlock(&zkrb_q_mutex), F)
|
28
44
|
|
29
|
-
/********************************************************************************
|
30
|
-
*
|
31
|
-
* NOTE: be *very careful* in these functions, calling *ANY* ruby interpreter
|
32
|
-
* function when you're not in an interpreter thread can hork ruby, trigger a
|
33
|
-
* [BUG], corrupt the stack, kill your dog, knock up your daughter, etc. etc.
|
34
|
-
*
|
35
|
-
*********************************************************************************
|
36
|
-
*/
|
37
45
|
|
38
|
-
/* push/pop is a misnomer, this is a queue */
|
39
46
|
void zkrb_enqueue(zkrb_queue_t *q, zkrb_event_t *elt) {
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
}
|
47
|
+
GLOBAL_MUTEX_LOCK("zkrb_enqueue");
|
48
|
+
|
49
|
+
check_debug(q != NULL && q->tail != NULL, "zkrb_enqueue: queue ptr or tail was NULL\n");
|
50
|
+
|
45
51
|
q->tail->event = elt;
|
46
52
|
q->tail->next = (struct zkrb_event_ll_t *) malloc(sizeof(struct zkrb_event_ll_t));
|
47
53
|
q->tail = q->tail->next;
|
48
54
|
q->tail->event = NULL;
|
49
55
|
q->tail->next = NULL;
|
50
56
|
ssize_t ret = write(q->pipe_write, "0", 1); /* Wake up Ruby listener */
|
51
|
-
pthread_mutex_unlock(&zkrb_q_mutex);
|
52
57
|
|
53
58
|
// XXX(slyphon): can't raise a ruby exception here as we may not be calling
|
54
59
|
// this from a ruby thread. Calling into the interpreter from a non-ruby
|
55
60
|
// thread is bad, mm'kay?
|
56
61
|
|
57
|
-
|
58
|
-
|
59
|
-
|
62
|
+
check(ret != -1, "write to queue (%p) pipe failed!\n", q);
|
63
|
+
|
64
|
+
error:
|
65
|
+
GLOBAL_MUTEX_UNLOCK("zkrb_enqueue");
|
60
66
|
}
|
61
67
|
|
68
|
+
// NOTE: the zkrb_event_t* returned *is* the same pointer that's part of the
|
69
|
+
// queue, the only place this is used is in method_has_events, and it is simply
|
70
|
+
// tested for null-ness. it's probably better to make the null-test here and
|
71
|
+
// not return the pointer
|
72
|
+
//
|
62
73
|
zkrb_event_t * zkrb_peek(zkrb_queue_t *q) {
|
63
|
-
pthread_mutex_lock(&zkrb_q_mutex);
|
64
74
|
zkrb_event_t *event = NULL;
|
75
|
+
|
76
|
+
GLOBAL_MUTEX_LOCK("zkrb_peek");
|
77
|
+
|
65
78
|
if (q != NULL && q->head != NULL && q->head->event != NULL) {
|
66
79
|
event = q->head->event;
|
67
80
|
}
|
68
|
-
|
81
|
+
|
82
|
+
GLOBAL_MUTEX_UNLOCK("zkrb_peek");
|
69
83
|
return event;
|
70
84
|
}
|
71
85
|
|
86
|
+
#define ZKRB_QUEUE_EMPTY(q) (q == NULL || q->head == NULL || q->head->event == NULL)
|
87
|
+
|
72
88
|
zkrb_event_t* zkrb_dequeue(zkrb_queue_t *q, int need_lock) {
|
89
|
+
zkrb_event_t *rv = NULL;
|
90
|
+
|
73
91
|
if (need_lock)
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
pthread_mutex_unlock(&zkrb_q_mutex);
|
78
|
-
return NULL;
|
79
|
-
} else {
|
92
|
+
GLOBAL_MUTEX_LOCK("zkrb_dequeue");
|
93
|
+
|
94
|
+
if (!ZKRB_QUEUE_EMPTY(q)) {
|
80
95
|
struct zkrb_event_ll_t *old_root = q->head;
|
81
96
|
q->head = q->head->next;
|
82
|
-
|
97
|
+
rv = old_root->event;
|
83
98
|
free(old_root);
|
84
|
-
if (need_lock)
|
85
|
-
pthread_mutex_unlock(&zkrb_q_mutex);
|
86
|
-
return rv;
|
87
99
|
}
|
100
|
+
|
101
|
+
if (need_lock)
|
102
|
+
GLOBAL_MUTEX_UNLOCK("zkrb_dequeue");
|
103
|
+
|
104
|
+
return rv;
|
88
105
|
}
|
89
106
|
|
90
107
|
void zkrb_signal(zkrb_queue_t *q) {
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
108
|
+
GLOBAL_MUTEX_LOCK("zkrb_signal");
|
109
|
+
|
110
|
+
if (!write(q->pipe_write, "0", 1)) /* Wake up Ruby listener */
|
111
|
+
log_err("zkrb_signal: write to pipe failed, could not wake");
|
112
|
+
|
113
|
+
GLOBAL_MUTEX_UNLOCK("zkrb_signal");
|
96
114
|
}
|
97
115
|
|
98
116
|
zkrb_queue_t *zkrb_queue_alloc(void) {
|
99
|
-
|
117
|
+
// some of the locking is a little coarse, but it
|
118
|
+
// eases the logic of releasing in case of error.
|
119
|
+
GLOBAL_MUTEX_LOCK("zkrb_queue_alloc");
|
100
120
|
|
101
|
-
|
121
|
+
int pfd[2];
|
122
|
+
zkrb_queue_t *rq = NULL;
|
123
|
+
|
124
|
+
check(pipe(pfd) == 0, "creating the signal pipe failed");
|
102
125
|
|
103
|
-
|
104
|
-
|
126
|
+
rq = malloc(sizeof(zkrb_queue_t));
|
127
|
+
check_mem(rq);
|
105
128
|
|
106
|
-
pthread_mutex_lock(&zkrb_q_mutex);
|
107
|
-
zkrb_queue_t *rq = malloc(sizeof(zkrb_queue_t));
|
108
129
|
rq->head = malloc(sizeof(struct zkrb_event_ll_t));
|
130
|
+
check_mem(rq->head);
|
131
|
+
|
109
132
|
rq->head->event = NULL; rq->head->next = NULL;
|
110
133
|
rq->tail = rq->head;
|
111
134
|
rq->pipe_read = pfd[0];
|
112
135
|
rq->pipe_write = pfd[1];
|
113
|
-
pthread_mutex_unlock(&zkrb_q_mutex);
|
114
136
|
|
137
|
+
GLOBAL_MUTEX_UNLOCK("zkrb_queue_alloc");
|
115
138
|
return rq;
|
139
|
+
|
140
|
+
error:
|
141
|
+
GLOBAL_MUTEX_UNLOCK("zkrb_queue_alloc");
|
142
|
+
return NULL;
|
116
143
|
}
|
117
144
|
|
118
145
|
void zkrb_queue_free(zkrb_queue_t *queue) {
|
119
|
-
|
120
|
-
|
121
|
-
pthread_mutex_unlock(&zkrb_q_mutex);
|
122
|
-
return;
|
123
|
-
}
|
146
|
+
GLOBAL_MUTEX_LOCK("zkrb_queue_free");
|
147
|
+
check_debug(queue != NULL, "zkrb_queue_free: queue was NULL");
|
124
148
|
|
125
149
|
zkrb_event_t *elt;
|
126
150
|
while ((elt = zkrb_dequeue(queue, 0)) != NULL) {
|
@@ -130,7 +154,9 @@ void zkrb_queue_free(zkrb_queue_t *queue) {
|
|
130
154
|
close(queue->pipe_read);
|
131
155
|
close(queue->pipe_write);
|
132
156
|
free(queue);
|
133
|
-
|
157
|
+
|
158
|
+
error:
|
159
|
+
GLOBAL_MUTEX_UNLOCK("zkrb_queue_free");
|
134
160
|
}
|
135
161
|
|
136
162
|
zkrb_event_t *zkrb_event_alloc(void) {
|
@@ -324,12 +350,10 @@ void zkrb_print_calling_context(zkrb_calling_context *ctx) {
|
|
324
350
|
|
325
351
|
void zkrb_state_callback(
|
326
352
|
zhandle_t *zh, int type, int state, const char *path, void *calling_ctx) {
|
327
|
-
|
328
|
-
|
329
|
-
fprintf(stderr, "ZOOKEEPER_C_STATE WATCHER "
|
353
|
+
|
354
|
+
zkrb_debug("ZOOKEEPER_C_STATE WATCHER "
|
330
355
|
"type = %d, state = %d, path = %p, value = %s\n",
|
331
356
|
type, state, (void *) path, path ? path : "NULL");
|
332
|
-
}
|
333
357
|
|
334
358
|
/* save callback context */
|
335
359
|
struct zkrb_watcher_completion *wc = malloc(sizeof(struct zkrb_watcher_completion));
|
@@ -358,11 +382,10 @@ void zkrb_state_callback(
|
|
358
382
|
|
359
383
|
void zkrb_data_callback(
|
360
384
|
int rc, const char *value, int value_len, const struct Stat *stat, const void *calling_ctx) {
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
}
|
385
|
+
|
386
|
+
zkrb_debug("ZOOKEEPER_C_DATA WATCHER "
|
387
|
+
"rc = %d (%s), value = %s, len = %d\n",
|
388
|
+
rc, zerror(rc), value ? value : "NULL", value_len);
|
366
389
|
|
367
390
|
/* copy data completion */
|
368
391
|
struct zkrb_data_completion *dc = malloc(sizeof(struct zkrb_data_completion));
|
@@ -388,10 +411,8 @@ void zkrb_data_callback(
|
|
388
411
|
|
389
412
|
void zkrb_stat_callback(
|
390
413
|
int rc, const struct Stat *stat, const void *calling_ctx) {
|
391
|
-
|
392
|
-
fprintf(stderr, "ZOOKEEPER_C_STAT WATCHER "
|
414
|
+
zkrb_debug("ZOOKEEPER_C_STAT WATCHER "
|
393
415
|
"rc = %d (%s)\n", rc, zerror(rc));
|
394
|
-
}
|
395
416
|
|
396
417
|
struct zkrb_stat_completion *sc = malloc(sizeof(struct zkrb_stat_completion));
|
397
418
|
sc->stat = NULL;
|
@@ -407,10 +428,9 @@ void zkrb_stat_callback(
|
|
407
428
|
|
408
429
|
void zkrb_string_callback(
|
409
430
|
int rc, const char *string, const void *calling_ctx) {
|
410
|
-
|
411
|
-
|
431
|
+
|
432
|
+
zkrb_debug("ZOOKEEPER_C_STRING WATCHER "
|
412
433
|
"rc = %d (%s)\n", rc, zerror(rc));
|
413
|
-
}
|
414
434
|
|
415
435
|
struct zkrb_string_completion *sc = malloc(sizeof(struct zkrb_string_completion));
|
416
436
|
sc->value = NULL;
|
@@ -427,10 +447,8 @@ void zkrb_string_callback(
|
|
427
447
|
|
428
448
|
void zkrb_strings_callback(
|
429
449
|
int rc, const struct String_vector *strings, const void *calling_ctx) {
|
430
|
-
|
431
|
-
fprintf(stderr, "ZOOKEEPER_C_STRINGS WATCHER "
|
450
|
+
zkrb_debug("ZOOKEEPER_C_STRINGS WATCHER "
|
432
451
|
"rc = %d (%s), calling_ctx = %p\n", rc, zerror(rc), calling_ctx);
|
433
|
-
}
|
434
452
|
|
435
453
|
/* copy string vector */
|
436
454
|
struct zkrb_strings_completion *sc = malloc(sizeof(struct zkrb_strings_completion));
|
@@ -446,10 +464,8 @@ void zkrb_strings_callback(
|
|
446
464
|
|
447
465
|
void zkrb_strings_stat_callback(
|
448
466
|
int rc, const struct String_vector *strings, const struct Stat *stat, const void *calling_ctx) {
|
449
|
-
|
450
|
-
fprintf(stderr, "ZOOKEEPER_C_STRINGS_STAT WATCHER "
|
467
|
+
zkrb_debug("ZOOKEEPER_C_STRINGS_STAT WATCHER "
|
451
468
|
"rc = %d (%s), calling_ctx = %p\n", rc, zerror(rc), calling_ctx);
|
452
|
-
}
|
453
469
|
|
454
470
|
struct zkrb_strings_stat_completion *sc = malloc(sizeof(struct zkrb_strings_stat_completion));
|
455
471
|
sc->stat = NULL;
|
@@ -465,12 +481,9 @@ void zkrb_strings_stat_callback(
|
|
465
481
|
zkrb_enqueue(queue, event);
|
466
482
|
}
|
467
483
|
|
468
|
-
void zkrb_void_callback(
|
469
|
-
|
470
|
-
if (ZKRBDebugging) {
|
471
|
-
fprintf(stderr, "ZOOKEEPER_C_VOID WATCHER "
|
484
|
+
void zkrb_void_callback(int rc, const void *calling_ctx) {
|
485
|
+
zkrb_debug("ZOOKEEPER_C_VOID WATCHER "
|
472
486
|
"rc = %d (%s)\n", rc, zerror(rc));
|
473
|
-
}
|
474
487
|
|
475
488
|
ZKH_SETUP_EVENT(queue, event);
|
476
489
|
event->rc = rc;
|
@@ -482,10 +495,7 @@ void zkrb_void_callback(
|
|
482
495
|
|
483
496
|
void zkrb_acl_callback(
|
484
497
|
int rc, struct ACL_vector *acls, struct Stat *stat, const void *calling_ctx) {
|
485
|
-
|
486
|
-
fprintf(stderr, "ZOOKEEPER_C_ACL WATCHER "
|
487
|
-
"rc = %d (%s)\n", rc, zerror(rc));
|
488
|
-
}
|
498
|
+
zkrb_debug("ZOOKEEPER_C_ACL WATCHER rc = %d (%s)\n", rc, zerror(rc));
|
489
499
|
|
490
500
|
struct zkrb_acl_completion *ac = malloc(sizeof(struct zkrb_acl_completion));
|
491
501
|
ac->acl = NULL;
|
@@ -644,3 +654,5 @@ struct String_vector * zkrb_clone_string_vector(const struct String_vector * src
|
|
644
654
|
}
|
645
655
|
return dst;
|
646
656
|
}
|
657
|
+
|
658
|
+
// vim:sts=2:sw=2:et
|
data/ext/zookeeper_lib.h
CHANGED
@@ -105,7 +105,6 @@ void zkrb_queue_free(zkrb_queue_t *queue);
|
|
105
105
|
zkrb_event_t * zkrb_event_alloc(void);
|
106
106
|
void zkrb_event_free(zkrb_event_t *ptr);
|
107
107
|
|
108
|
-
/* push/pop is a misnomer, this is a queue */
|
109
108
|
void zkrb_enqueue(zkrb_queue_t *queue, zkrb_event_t *elt);
|
110
109
|
zkrb_event_t * zkrb_peek(zkrb_queue_t *queue);
|
111
110
|
zkrb_event_t * zkrb_dequeue(zkrb_queue_t *queue, int need_lock);
|