Add files using upload-large-folder tool
Browse files- local-test-zookeeper-full-01/afc-zookeeper/zookeeper-contrib/zookeeper-contrib-fatjar/README.md +21 -0
- local-test-zookeeper-full-01/afc-zookeeper/zookeeper-contrib/zookeeper-contrib-loggraph/README.md +80 -0
- local-test-zookeeper-full-01/afc-zookeeper/zookeeper-contrib/zookeeper-contrib-monitoring/test.py +282 -0
- local-test-zookeeper-full-01/afc-zookeeper/zookeeper-contrib/zookeeper-contrib-rest/NOTICE.txt +7 -0
- local-test-zookeeper-full-01/afc-zookeeper/zookeeper-contrib/zookeeper-contrib-zkfuse/README.txt +63 -0
- local-test-zookeeper-full-01/afc-zookeeper/zookeeper-contrib/zookeeper-contrib-zkfuse/build.xml +61 -0
- local-test-zookeeper-full-01/afc-zookeeper/zookeeper-contrib/zookeeper-contrib-zkperl/Changes +65 -0
- local-test-zookeeper-full-01/afc-zookeeper/zookeeper-contrib/zookeeper-contrib-zkperl/MANIFEST +23 -0
- local-test-zookeeper-full-01/afc-zookeeper/zookeeper-contrib/zookeeper-contrib-zkperl/Makefile.PL +87 -0
- local-test-zookeeper-full-01/afc-zookeeper/zookeeper-contrib/zookeeper-contrib-zkperl/NOTICE +6 -0
- local-test-zookeeper-full-01/afc-zookeeper/zookeeper-contrib/zookeeper-contrib-zkperl/ZooKeeper.pm +1285 -0
- local-test-zookeeper-full-01/afc-zookeeper/zookeeper-contrib/zookeeper-contrib-zkperl/ZooKeeper.xs +2722 -0
- local-test-zookeeper-full-01/afc-zookeeper/zookeeper-contrib/zookeeper-contrib-zkperl/typemap +38 -0
- local-test-zookeeper-full-01/afc-zookeeper/zookeeper-contrib/zookeeper-contrib-zooinspector/NOTICE.txt +9 -0
- local-test-zookeeper-full-01/afc-zookeeper/zookeeper-contrib/zookeeper-contrib-zooinspector/README.txt +102 -0
- local-test-zookeeper-full-01/afc-zookeeper/zookeeper-contrib/zookeeper-contrib-zooinspector/TODO +19 -0
- local-test-zookeeper-full-01/afc-zookeeper/zookeeper-contrib/zookeeper-contrib-zooinspector/zooInspector-dev.sh +18 -0
- local-test-zookeeper-full-01/afc-zookeeper/zookeeper-contrib/zookeeper-contrib-zooinspector/zooInspector.cmd +26 -0
- local-test-zookeeper-full-01/afc-zookeeper/zookeeper-contrib/zookeeper-contrib-zooinspector/zooInspector.sh +25 -0
- local-test-zookeeper-full-01/afc-zookeeper/zookeeper-server/src/test/resources/data/buffersize/set/version-2/log.1 +0 -0
local-test-zookeeper-full-01/afc-zookeeper/zookeeper-contrib/zookeeper-contrib-fatjar/README.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
ZooKeeper Fatjar
|
| 2 |
+
================
|
| 3 |
+
|
| 4 |
+
This package contains build to create a fat zookeeper jar. Fatjar can be used to run:
|
| 5 |
+
- zookeeper server
|
| 6 |
+
- zookeeper client
|
| 7 |
+
- distributed load generator for testing (generateLoad)
|
| 8 |
+
- container that will instantiate classes as directed by an instance manager (ic)
|
| 9 |
+
- system test (systest)
|
| 10 |
+
- jmh micro benchmarks (jmh)
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
Use following command to build fatjar
|
| 14 |
+
```
|
| 15 |
+
mvn clean install -P fatjar -DskipTests
|
| 16 |
+
```
|
| 17 |
+
|
| 18 |
+
To run the fatjar use:
|
| 19 |
+
```
|
| 20 |
+
java -jar zoookeeper-<version>-fatjar.jar
|
| 21 |
+
```
|
local-test-zookeeper-full-01/afc-zookeeper/zookeeper-contrib/zookeeper-contrib-loggraph/README.md
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# LogGraph README
|
| 2 |
+
|
| 3 |
+
## 1 - About
|
| 4 |
+
LogGraph is an application for viewing and filtering zookeeper logs. It can handle transaction logs and message logs.
|
| 5 |
+
|
| 6 |
+
## 2 - Compiling
|
| 7 |
+
|
| 8 |
+
Run `mvn clean install dependency:copy-dependencies` in zookeeper-contrib/zookeeper-contrib-loggraph/.
|
| 9 |
+
This will download all dependencies and compile all the loggraph code.
|
| 10 |
+
|
| 11 |
+
Once compilation has finished, you can run it the the `loggraph.sh` script in zookeeper-contrib/zookeeper-contrib-loggraph/src/main/resources.
|
| 12 |
+
This will start and embedded web server on your machine.
|
| 13 |
+
Navigate to `http://localhost:8182/graph/main.html`
|
| 14 |
+
|
| 15 |
+
## 3 - Usage
|
| 16 |
+
LogGraph presents the user with 4 views,
|
| 17 |
+
|
| 18 |
+
a) Simple log view
|
| 19 |
+
This view simply displays the log text. This isn't very useful without filters (see "Filtering the logs").
|
| 20 |
+
|
| 21 |
+
b) Server view
|
| 22 |
+
The server view shows the interactions between the different servers in an ensemble. The X axis represents time.
|
| 23 |
+
|
| 24 |
+
* Exceptions show up as red dots. Hovering your mouse over them will give you more details of the exception
|
| 25 |
+
* The colour of the line represents the election state of the server.
|
| 26 |
+
- orange means LOOKING for leader
|
| 27 |
+
- dark green means the server is the leader
|
| 28 |
+
- light green means the server is following a leader
|
| 29 |
+
- yellow means there isn't enough information to determine the state of the server.
|
| 30 |
+
* The gray arrows denote election messages between servers. Pink dashed arrows are messages that were sent but never delivered.
|
| 31 |
+
|
| 32 |
+
c) Session view
|
| 33 |
+
The session view shows the lifetime of sessions on a server. Use the time filter to narrow down the view. Any more than about 2000 events will take a long time to view in your browser.
|
| 34 |
+
The X axis represents time. Each line is a session. The black dots represent events on the session. You can click on the black dots for more details of the event.
|
| 35 |
+
|
| 36 |
+
d) Stats view
|
| 37 |
+
There is currently only one statistics view, Transactions/minute. Suggestions for other statistic views are very welcome.
|
| 38 |
+
|
| 39 |
+
## 4 - Filtering the logs
|
| 40 |
+
The logs can be filtered in 2 ways, by time and by content.
|
| 41 |
+
|
| 42 |
+
To filter by time simply move the slider to the desired start time. The time window specifies how many milliseconds after and including the start time will be displayed.
|
| 43 |
+
|
| 44 |
+
Content filtering uses a adhoc filtering language, using prefix notation. The language looks somewhat similar to lisp. A statement in the language takes the form (op arg arg ....). A statement resolves to a boolean value. Statements can be nested.
|
| 45 |
+
|
| 46 |
+
### 4.1 - Filter arguments
|
| 47 |
+
An argument can be a number, a string or a symbol. A number is any argument which starts with -, + or 0 to 9. If the number starts with 0x it is interpreted as hexadecimal. Otherwise it is interpreted as decimal. If the argument begins with a double-quote, (") it is interpreted as a string. Anything else is interpreted as a symbol.
|
| 48 |
+
|
| 49 |
+
### 4.2 - Filter symbols
|
| 50 |
+
The possible filter symbols are:
|
| 51 |
+
|
| 52 |
+
client-id : number, the session id of the client who initiated a transaction.
|
| 53 |
+
|
| 54 |
+
cxid : number, the cxid of a transaction
|
| 55 |
+
|
| 56 |
+
zxid : number, the zxid of a transaction
|
| 57 |
+
|
| 58 |
+
operation : string, the operation being performed, for example "setData", "createSession", "closeSession", "error", "create"
|
| 59 |
+
|
| 60 |
+
### 4.3 - Filter operations
|
| 61 |
+
The possible filter operations are:
|
| 62 |
+
|
| 63 |
+
or : logical or, takes 1 or more arguments which must be other statements.
|
| 64 |
+
|
| 65 |
+
and : logical and, takes 1 or more arguments which must be other statements.
|
| 66 |
+
|
| 67 |
+
not : logical not, takes 1 argument which must be another statement.
|
| 68 |
+
|
| 69 |
+
xor : exclusive or, takes 1 or more arguments which must be other statements.
|
| 70 |
+
|
| 71 |
+
= : equals, takes 1 or more arguments, which must all be equal to each other to return true.
|
| 72 |
+
|
| 73 |
+
> : greater than, takes 1 or more arguments, to return true the 1st argument must be greater than the 2nd argument which must be greater than the 3rd argument and so on...
|
| 74 |
+
|
| 75 |
+
< : less than, takes 1 or more arguments, to return true the 1st argument must be less than the 2nd argument which must be less than the 3rd argument and so on...
|
| 76 |
+
|
| 77 |
+
### 4.4 - Filter examples
|
| 78 |
+
Give me all the setData operations with session id 0xdeadbeef or 0xcafeb33r but not with zxid 0x12341234 ->
|
| 79 |
+
|
| 80 |
+
(and (= operation "setData") (or (= client-id 0xdeadbeef) (= client-id 0xcafeb33r)) (not (= zxid 0x12341234)))
|
local-test-zookeeper-full-01/afc-zookeeper/zookeeper-contrib/zookeeper-contrib-monitoring/test.py
ADDED
|
@@ -0,0 +1,282 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#! /usr/bin/env python
|
| 2 |
+
# Licensed to the Apache Software Foundation (ASF) under one
|
| 3 |
+
# or more contributor license agreements. See the NOTICE file
|
| 4 |
+
# distributed with this work for additional information
|
| 5 |
+
# regarding copyright ownership. The ASF licenses this file
|
| 6 |
+
# to you under the Apache License, Version 2.0 (the
|
| 7 |
+
# "License"); you may not use this file except in compliance
|
| 8 |
+
# with the License. You may obtain a copy of the License at
|
| 9 |
+
|
| 10 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 11 |
+
|
| 12 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 13 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 14 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 15 |
+
# See the License for the specific language governing permissions and
|
| 16 |
+
# limitations under the License.
|
| 17 |
+
|
| 18 |
+
import unittest
|
| 19 |
+
import socket
|
| 20 |
+
import sys
|
| 21 |
+
|
| 22 |
+
from StringIO import StringIO
|
| 23 |
+
|
| 24 |
+
from check_zookeeper import ZooKeeperServer, NagiosHandler, CactiHandler, GangliaHandler
|
| 25 |
+
|
| 26 |
+
ZK_MNTR_OUTPUT = """zk_version\t3.4.0--1, built on 06/19/2010 15:07 GMT
|
| 27 |
+
zk_avg_latency\t1
|
| 28 |
+
zk_max_latency\t132
|
| 29 |
+
zk_min_latency\t0
|
| 30 |
+
zk_packets_received\t640
|
| 31 |
+
zk_packets_sent\t639
|
| 32 |
+
zk_outstanding_requests\t0
|
| 33 |
+
zk_server_state\tfollower
|
| 34 |
+
zk_znode_count\t4
|
| 35 |
+
zk_watch_count\t0
|
| 36 |
+
zk_ephemerals_count\t0
|
| 37 |
+
zk_approximate_data_size\t27
|
| 38 |
+
zk_open_file_descriptor_count\t22
|
| 39 |
+
zk_max_file_descriptor_count\t1024
|
| 40 |
+
"""
|
| 41 |
+
|
| 42 |
+
ZK_MNTR_OUTPUT_WITH_BROKEN_LINES = """zk_version\t3.4.0
|
| 43 |
+
zk_avg_latency\t23
|
| 44 |
+
broken-line
|
| 45 |
+
|
| 46 |
+
"""
|
| 47 |
+
|
| 48 |
+
ZK_STAT_OUTPUT = """Zookeeper version: 3.3.0-943314, built on 05/11/2010 22:20 GMT
|
| 49 |
+
Clients:
|
| 50 |
+
/0:0:0:0:0:0:0:1:34564[0](queued=0,recved=1,sent=0)
|
| 51 |
+
|
| 52 |
+
Latency min/avg/max: 0/40/121
|
| 53 |
+
Received: 11
|
| 54 |
+
Sent: 10
|
| 55 |
+
Outstanding: 0
|
| 56 |
+
Zxid: 0x700000003
|
| 57 |
+
Mode: follower
|
| 58 |
+
Node count: 4
|
| 59 |
+
"""
|
| 60 |
+
|
| 61 |
+
class SocketMock(object):
|
| 62 |
+
def __init__(self):
|
| 63 |
+
self.sent = []
|
| 64 |
+
|
| 65 |
+
def settimeout(self, timeout):
|
| 66 |
+
self.timeout = timeout
|
| 67 |
+
|
| 68 |
+
def connect(self, address):
|
| 69 |
+
self.address = address
|
| 70 |
+
|
| 71 |
+
def send(self, data):
|
| 72 |
+
self.sent.append(data)
|
| 73 |
+
return len(data)
|
| 74 |
+
|
| 75 |
+
def recv(self, size):
|
| 76 |
+
return ZK_MNTR_OUTPUT[:size]
|
| 77 |
+
|
| 78 |
+
def close(self): pass
|
| 79 |
+
|
| 80 |
+
class ZK33xSocketMock(SocketMock):
|
| 81 |
+
def __init__(self):
|
| 82 |
+
SocketMock.__init__(self)
|
| 83 |
+
self.got_stat_cmd = False
|
| 84 |
+
|
| 85 |
+
def recv(self, size):
|
| 86 |
+
if 'stat' in self.sent:
|
| 87 |
+
return ZK_STAT_OUTPUT[:size]
|
| 88 |
+
else:
|
| 89 |
+
return ''
|
| 90 |
+
|
| 91 |
+
class UnableToConnectSocketMock(SocketMock):
|
| 92 |
+
def connect(self, _):
|
| 93 |
+
raise socket.error('[Errno 111] Connection refused')
|
| 94 |
+
|
| 95 |
+
def create_server_mock(socket_class):
|
| 96 |
+
class ZooKeeperServerMock(ZooKeeperServer):
|
| 97 |
+
def _create_socket(self):
|
| 98 |
+
return socket_class()
|
| 99 |
+
return ZooKeeperServerMock()
|
| 100 |
+
|
| 101 |
+
class TestCheckZookeeper(unittest.TestCase):
|
| 102 |
+
|
| 103 |
+
def setUp(self):
|
| 104 |
+
self.zk = ZooKeeperServer()
|
| 105 |
+
|
| 106 |
+
def test_parse_valid_line(self):
|
| 107 |
+
key, value = self.zk._parse_line('something\t5')
|
| 108 |
+
|
| 109 |
+
self.assertEqual(key, 'something')
|
| 110 |
+
self.assertEqual(value, 5)
|
| 111 |
+
|
| 112 |
+
def test_parse_line_raises_exception_on_invalid_output(self):
|
| 113 |
+
invalid_lines = ['something', '', 'a\tb\tc', '\t1']
|
| 114 |
+
for line in invalid_lines:
|
| 115 |
+
self.assertRaises(ValueError, self.zk._parse_line, line)
|
| 116 |
+
|
| 117 |
+
def test_parser_on_valid_output(self):
|
| 118 |
+
data = self.zk._parse(ZK_MNTR_OUTPUT)
|
| 119 |
+
|
| 120 |
+
self.assertEqual(len(data), 14)
|
| 121 |
+
self.assertEqual(data['zk_znode_count'], 4)
|
| 122 |
+
|
| 123 |
+
def test_parse_should_ignore_invalid_lines(self):
|
| 124 |
+
data = self.zk._parse(ZK_MNTR_OUTPUT_WITH_BROKEN_LINES)
|
| 125 |
+
|
| 126 |
+
self.assertEqual(len(data), 2)
|
| 127 |
+
|
| 128 |
+
def test_parse_stat_valid_output(self):
|
| 129 |
+
data = self.zk._parse_stat(ZK_STAT_OUTPUT)
|
| 130 |
+
|
| 131 |
+
result = {
|
| 132 |
+
'zk_version' : '3.3.0-943314, built on 05/11/2010 22:20 GMT',
|
| 133 |
+
'zk_min_latency' : 0,
|
| 134 |
+
'zk_avg_latency' : 40,
|
| 135 |
+
'zk_max_latency' : 121,
|
| 136 |
+
'zk_packets_received': 11,
|
| 137 |
+
'zk_packets_sent': 10,
|
| 138 |
+
'zk_server_state': 'follower',
|
| 139 |
+
'zk_znode_count': 4
|
| 140 |
+
}
|
| 141 |
+
for k, v in result.iteritems():
|
| 142 |
+
self.assertEqual(v, data[k])
|
| 143 |
+
|
| 144 |
+
def test_recv_valid_output(self):
|
| 145 |
+
zk = create_server_mock(SocketMock)
|
| 146 |
+
|
| 147 |
+
data = zk.get_stats()
|
| 148 |
+
self.assertEqual(len(data), 14)
|
| 149 |
+
self.assertEqual(data['zk_znode_count'], 4)
|
| 150 |
+
|
| 151 |
+
def test_socket_unable_to_connect(self):
|
| 152 |
+
zk = create_server_mock(UnableToConnectSocketMock)
|
| 153 |
+
|
| 154 |
+
self.assertRaises(socket.error, zk.get_stats)
|
| 155 |
+
|
| 156 |
+
def test_use_stat_cmd_if_mntr_is_not_available(self):
|
| 157 |
+
zk = create_server_mock(ZK33xSocketMock)
|
| 158 |
+
|
| 159 |
+
data = zk.get_stats()
|
| 160 |
+
self.assertEqual(data['zk_version'], '3.3.0-943314, built on 05/11/2010 22:20 GMT')
|
| 161 |
+
|
| 162 |
+
class HandlerTestCase(unittest.TestCase):
|
| 163 |
+
|
| 164 |
+
def setUp(self):
|
| 165 |
+
try:
|
| 166 |
+
sys._stdout
|
| 167 |
+
except:
|
| 168 |
+
sys._stdout = sys.stdout
|
| 169 |
+
|
| 170 |
+
sys.stdout = StringIO()
|
| 171 |
+
|
| 172 |
+
def tearDown(self):
|
| 173 |
+
sys.stdout = sys._stdout
|
| 174 |
+
|
| 175 |
+
def output(self):
|
| 176 |
+
sys.stdout.seek(0)
|
| 177 |
+
return sys.stdout.read()
|
| 178 |
+
|
| 179 |
+
|
| 180 |
+
class TestNagiosHandler(HandlerTestCase):
|
| 181 |
+
|
| 182 |
+
def _analyze(self, w, c, k, stats):
|
| 183 |
+
class Opts(object):
|
| 184 |
+
warning = w
|
| 185 |
+
critical = c
|
| 186 |
+
key = k
|
| 187 |
+
|
| 188 |
+
return NagiosHandler().analyze(Opts(), {'localhost:2181':stats})
|
| 189 |
+
|
| 190 |
+
def test_ok_status(self):
|
| 191 |
+
r = self._analyze(10, 20, 'a', {'a': 5})
|
| 192 |
+
|
| 193 |
+
self.assertEqual(r, 0)
|
| 194 |
+
self.assertEqual(self.output(), 'Ok "a"!|localhost:2181=5;10;20\n')
|
| 195 |
+
|
| 196 |
+
r = self._analyze(20, 10, 'a', {'a': 30})
|
| 197 |
+
self.assertEqual(r, 0)
|
| 198 |
+
|
| 199 |
+
def test_warning_status(self):
|
| 200 |
+
r = self._analyze(10, 20, 'a', {'a': 15})
|
| 201 |
+
self.assertEqual(r, 1)
|
| 202 |
+
self.assertEqual(self.output(),
|
| 203 |
+
'Warning "a" localhost:2181!|localhost:2181=15;10;20\n')
|
| 204 |
+
|
| 205 |
+
r = self._analyze(20, 10, 'a', {'a': 15})
|
| 206 |
+
self.assertEqual(r, 1)
|
| 207 |
+
|
| 208 |
+
def test_critical_status(self):
|
| 209 |
+
r = self._analyze(10, 20, 'a', {'a': 30})
|
| 210 |
+
self.assertEqual(r, 2)
|
| 211 |
+
self.assertEqual(self.output(),
|
| 212 |
+
'Critical "a" localhost:2181!|localhost:2181=30;10;20\n')
|
| 213 |
+
|
| 214 |
+
r = self._analyze(20, 10, 'a', {'a': 5})
|
| 215 |
+
self.assertEqual(r, 2)
|
| 216 |
+
|
| 217 |
+
def test_check_a_specific_key_on_all_hosts(self):
|
| 218 |
+
class Opts(object):
|
| 219 |
+
warning = 10
|
| 220 |
+
critical = 20
|
| 221 |
+
key = 'latency'
|
| 222 |
+
|
| 223 |
+
r = NagiosHandler().analyze(Opts(), {
|
| 224 |
+
's1:2181': {'latency': 5},
|
| 225 |
+
's2:2181': {'latency': 15},
|
| 226 |
+
's3:2181': {'latency': 35},
|
| 227 |
+
})
|
| 228 |
+
self.assertEqual(r, 2)
|
| 229 |
+
self.assertEqual(self.output(),
|
| 230 |
+
'Critical "latency" s3:2181!|s1:2181=5;10;20 '\
|
| 231 |
+
's3:2181=35;10;20 s2:2181=15;10;20\n')
|
| 232 |
+
|
| 233 |
+
class TestCactiHandler(HandlerTestCase):
|
| 234 |
+
class Opts(object):
|
| 235 |
+
key = 'a'
|
| 236 |
+
leader = False
|
| 237 |
+
|
| 238 |
+
def __init__(self, leader=False):
|
| 239 |
+
self.leader = leader
|
| 240 |
+
|
| 241 |
+
def test_output_values_for_all_hosts(self):
|
| 242 |
+
r = CactiHandler().analyze(TestCactiHandler.Opts(), {
|
| 243 |
+
's1:2181':{'a':1},
|
| 244 |
+
's2:2181':{'a':2, 'b':3}
|
| 245 |
+
})
|
| 246 |
+
self.assertEqual(r, None)
|
| 247 |
+
self.assertEqual(self.output(), 's1_2181:1 s2_2181:2')
|
| 248 |
+
|
| 249 |
+
def test_output_single_value_for_leader(self):
|
| 250 |
+
r = CactiHandler().analyze(TestCactiHandler.Opts(leader=True), {
|
| 251 |
+
's1:2181': {'a':1, 'zk_server_state': 'leader'},
|
| 252 |
+
's2:2181': {'a':2}
|
| 253 |
+
})
|
| 254 |
+
self.assertEqual(r, 0)
|
| 255 |
+
self.assertEqual(self.output(), '1\n')
|
| 256 |
+
|
| 257 |
+
|
| 258 |
+
class TestGangliaHandler(unittest.TestCase):
|
| 259 |
+
|
| 260 |
+
class TestableGangliaHandler(GangliaHandler):
|
| 261 |
+
def __init__(self):
|
| 262 |
+
GangliaHandler.__init__(self)
|
| 263 |
+
self.cli_calls = []
|
| 264 |
+
|
| 265 |
+
def call(self, cli):
|
| 266 |
+
self.cli_calls.append(' '.join(cli))
|
| 267 |
+
|
| 268 |
+
def test_send_single_metric(self):
|
| 269 |
+
class Opts(object):
|
| 270 |
+
@property
|
| 271 |
+
def gmetric(self): return '/usr/bin/gmetric'
|
| 272 |
+
opts = Opts()
|
| 273 |
+
|
| 274 |
+
h = TestGangliaHandler.TestableGangliaHandler()
|
| 275 |
+
h.analyze(opts, {'localhost:2181':{'latency':10}})
|
| 276 |
+
|
| 277 |
+
cmd = "%s -n latency -v 10 -t uint32" % opts.gmetric
|
| 278 |
+
assert cmd in h.cli_calls
|
| 279 |
+
|
| 280 |
+
if __name__ == '__main__':
|
| 281 |
+
unittest.main()
|
| 282 |
+
|
local-test-zookeeper-full-01/afc-zookeeper/zookeeper-contrib/zookeeper-contrib-rest/NOTICE.txt
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
This contrib module includes software developed under the
|
| 2 |
+
COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0
|
| 3 |
+
|
| 4 |
+
This contrib depends on binary only jar libraries developed at:
|
| 5 |
+
|
| 6 |
+
https://jersey.dev.java.net/
|
| 7 |
+
https://grizzly.dev.java.net/
|
local-test-zookeeper-full-01/afc-zookeeper/zookeeper-contrib/zookeeper-contrib-zkfuse/README.txt
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Original authors of zkfuse are Swee Lim & Bartlomiej M Niechwiej of Yahoo.
|
| 2 |
+
'
|
| 3 |
+
ZooKeeper FUSE (File System in Userspace)
|
| 4 |
+
=========================================
|
| 5 |
+
|
| 6 |
+
Pre-requisites
|
| 7 |
+
--------------
|
| 8 |
+
1. Linux system with 2.6.X kernel.
|
| 9 |
+
2. Fuse (Filesystem in Userspace) must be installed on the build node.
|
| 10 |
+
3. Development build libraries:
|
| 11 |
+
a. fuse
|
| 12 |
+
b. log4cxx
|
| 13 |
+
c. pthread
|
| 14 |
+
d. boost
|
| 15 |
+
|
| 16 |
+
Build instructions
|
| 17 |
+
------------------
|
| 18 |
+
1. cd into this directory
|
| 19 |
+
2. autoreconf -if
|
| 20 |
+
3. ./configure
|
| 21 |
+
4. make
|
| 22 |
+
5. zkfuse binary is under the src directory
|
| 23 |
+
|
| 24 |
+
Testing Zkfuse
|
| 25 |
+
--------------
|
| 26 |
+
1. Depending on permission on /dev/fuse, you may need to sudo -u root.
|
| 27 |
+
* If /dev/fuse has permissions 0600, then you have to run Zkfuse as root.
|
| 28 |
+
* If /dev/fuse has permissions 0666, then you can run Zkfuse as any user.
|
| 29 |
+
2. Create or find a mount point that you have "rwx" permission.
|
| 30 |
+
* e.g. mkdir -p /tmp/zkfuse
|
| 31 |
+
3. Run Zkfuse as follows:
|
| 32 |
+
zkfuse -z <hostspec> -m /tmp/zkfuse -d
|
| 33 |
+
-z specifies ZooKeeper address(es) <host>:<port>
|
| 34 |
+
-m specifies the mount point
|
| 35 |
+
-d specifies the debug mode.
|
| 36 |
+
For additional command line options, try "zkfuse -h".
|
| 37 |
+
|
| 38 |
+
FAQ
|
| 39 |
+
---
|
| 40 |
+
Q. How to fix "warning: macro `AM_PATH_CPPUNIT' not found in library"?
|
| 41 |
+
A. * install cppunit (src or pkg) on build machine
|
| 42 |
+
|
| 43 |
+
Q. Why can't Zkfuse cannot write to current directory?
|
| 44 |
+
A. * If Zkfuse is running as root on a NFS mounted file system, it will not
|
| 45 |
+
have root permissions because root user is mapped to another user by
|
| 46 |
+
NFS admin.
|
| 47 |
+
* If you run Zkfuse as root, it is a good idea to run Zkfuse from a
|
| 48 |
+
directory that you have write access to. This will allow core files
|
| 49 |
+
to be saved.
|
| 50 |
+
|
| 51 |
+
Q. Why Zkfuse cannot mount?
|
| 52 |
+
A. * Check that the mount point exists and you have "rwx" permissions.
|
| 53 |
+
* Check that previous mounts have been umounted. If Zkfuse does not
|
| 54 |
+
exit cleanly, its mount point may have to be umounted manually.
|
| 55 |
+
If you cannot umount manually, make sure that there no files is open
|
| 56 |
+
within the mount point.
|
| 57 |
+
|
| 58 |
+
Q. Why does Zkfuse complain about logging at startup?
|
| 59 |
+
A. * Zkfuse uses log4cxx for logging. It is looking for log4cxx.properties
|
| 60 |
+
file to obtain its logging configuration.
|
| 61 |
+
* There is an example log4cxx.properties file in the Zkfuse source
|
| 62 |
+
directory.
|
| 63 |
+
|
local-test-zookeeper-full-01/afc-zookeeper/zookeeper-contrib/zookeeper-contrib-zkfuse/build.xml
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?xml version="1.0"?>
|
| 2 |
+
|
| 3 |
+
<!--
|
| 4 |
+
Licensed to the Apache Software Foundation (ASF) under one or more
|
| 5 |
+
contributor license agreements. See the NOTICE file distributed with
|
| 6 |
+
this work for additional information regarding copyright ownership.
|
| 7 |
+
The ASF licenses this file to You under the Apache License, Version 2.0
|
| 8 |
+
(the "License"); you may not use this file except in compliance with
|
| 9 |
+
the License. You may obtain a copy of the License at
|
| 10 |
+
|
| 11 |
+
http://www.apache.org/licenses/LICENSE-2.0
|
| 12 |
+
|
| 13 |
+
Unless required by applicable law or agreed to in writing, software
|
| 14 |
+
distributed under the License is distributed on an "AS IS" BASIS,
|
| 15 |
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 16 |
+
See the License for the specific language governing permissions and
|
| 17 |
+
limitations under the License.
|
| 18 |
+
-->
|
| 19 |
+
|
| 20 |
+
<project name="zkfuse" default="compile">
|
| 21 |
+
<import file="../build-contrib.xml"/>
|
| 22 |
+
|
| 23 |
+
<target name="init" depends="check-contrib" unless="skip.contrib">
|
| 24 |
+
<echo message="contrib: ${name}"/>
|
| 25 |
+
<mkdir dir="${build.dir}"/>
|
| 26 |
+
<antcall target="init-contrib"/>
|
| 27 |
+
</target>
|
| 28 |
+
|
| 29 |
+
<target name="compile" depends="init" unless="skip.contrib">
|
| 30 |
+
<echo message="contrib: ${name}"/>
|
| 31 |
+
|
| 32 |
+
<mkdir dir="${build.dir}"/>
|
| 33 |
+
<copy todir="${build.dir}">
|
| 34 |
+
<fileset dir="${basedir}">
|
| 35 |
+
<exclude name="**/VERSION"/>
|
| 36 |
+
</fileset>
|
| 37 |
+
</copy>
|
| 38 |
+
<exec executable="echo" output="${build.dir}/VERSION">
|
| 39 |
+
<arg line="${version}" />
|
| 40 |
+
</exec>
|
| 41 |
+
</target>
|
| 42 |
+
|
| 43 |
+
<target name="jar" depends="compile" >
|
| 44 |
+
<echo message="No jar target defined for this package"/>
|
| 45 |
+
</target>
|
| 46 |
+
|
| 47 |
+
<target name="test">
|
| 48 |
+
<echo message="No test target defined for this package" />
|
| 49 |
+
</target>
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
<target name="package" depends="compile" unless="skip.contrib">
|
| 53 |
+
<echo message="contrib: ${name}"/>
|
| 54 |
+
|
| 55 |
+
<mkdir dir="${dist.dir}/zookeeper-contrib/zookeeper-contrib-${name}"/>
|
| 56 |
+
<copy todir="${dist.dir}/zookeeper-contrib/zookeeper-contrib-${name}">
|
| 57 |
+
<fileset dir="${build.dir}"/>
|
| 58 |
+
</copy>
|
| 59 |
+
</target>
|
| 60 |
+
|
| 61 |
+
</project>
|
local-test-zookeeper-full-01/afc-zookeeper/zookeeper-contrib/zookeeper-contrib-zkperl/Changes
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Net::ZooKeeper - Perl extension for Apache ZooKeeper
|
| 2 |
+
|
| 3 |
+
Revision history
|
| 4 |
+
================
|
| 5 |
+
|
| 6 |
+
0.01 Dec 5, 2008
|
| 7 |
+
- initial version
|
| 8 |
+
|
| 9 |
+
0.02 Dec 16, 2008
|
| 10 |
+
- support connection to ZooKeeper and get() method
|
| 11 |
+
|
| 12 |
+
0.03 Jan 9, 2009
|
| 13 |
+
- implemented watch mechanism for get()
|
| 14 |
+
|
| 15 |
+
0.04 Jan 15, 2009
|
| 16 |
+
- all basic ZooKeeper methods supported
|
| 17 |
+
|
| 18 |
+
0.05 Jan 21, 2009
|
| 19 |
+
- converted from T_PTROBJ to T_ZK_HASH with PERL_MAGIC_ext,
|
| 20 |
+
allows DESTROY() to be called repeatedly
|
| 21 |
+
|
| 22 |
+
0.06 Jan 27, 2009
|
| 23 |
+
- converted from attribute accessor methods to inner and outer hashes
|
| 24 |
+
with PERL_MAGIC_tied
|
| 25 |
+
|
| 26 |
+
0.07 Jan 29, 2009
|
| 27 |
+
- all tied hash methods completed
|
| 28 |
+
|
| 29 |
+
0.08 Jan 30, 2009
|
| 30 |
+
- simple thread safety enforced with CLONE_SKIP
|
| 31 |
+
|
| 32 |
+
0.09 Feb 12, 2009
|
| 33 |
+
- ACL constants
|
| 34 |
+
|
| 35 |
+
0.10 Feb 18, 2009
|
| 36 |
+
- ACL support
|
| 37 |
+
|
| 38 |
+
0.11 Feb 21, 2009
|
| 39 |
+
- ZooKeeper version check
|
| 40 |
+
|
| 41 |
+
0.20 Feb 25, 2009
|
| 42 |
+
- refactored watches as subclass
|
| 43 |
+
|
| 44 |
+
0.30 Feb 27, 2009
|
| 45 |
+
- refactored stats as subclass
|
| 46 |
+
|
| 47 |
+
0.31 Mar 6, 2009
|
| 48 |
+
- test suite completed
|
| 49 |
+
|
| 50 |
+
0.32 Mar 25, 2009
|
| 51 |
+
- initial documentation completed, first public release
|
| 52 |
+
|
| 53 |
+
0.33 Apr 20, 2009
|
| 54 |
+
- copyright donated to ASF
|
| 55 |
+
|
| 56 |
+
0.34 Jul 14, 2009
|
| 57 |
+
- support ZooKeeper 3.2.0 release
|
| 58 |
+
|
| 59 |
+
0.35 Jul 15, 2009
|
| 60 |
+
- support multiple include and library locations
|
| 61 |
+
|
| 62 |
+
0.36 Mar 27, 2011
|
| 63 |
+
- Fix zookeeper version check, but only warn since we haven't been enforcing it in a while
|
| 64 |
+
- Look for zookeeper includes in some sane places by default
|
| 65 |
+
|
local-test-zookeeper-full-01/afc-zookeeper/zookeeper-contrib/zookeeper-contrib-zkperl/MANIFEST
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Changes
|
| 2 |
+
LICENSE
|
| 3 |
+
Makefile.PL
|
| 4 |
+
MANIFEST
|
| 5 |
+
NOTICE
|
| 6 |
+
README
|
| 7 |
+
typemap
|
| 8 |
+
ZooKeeper.pm
|
| 9 |
+
ZooKeeper.xs
|
| 10 |
+
build/check_zk_version.c
|
| 11 |
+
build/check_zk_version.h
|
| 12 |
+
t/10_invalid.t
|
| 13 |
+
t/15_thread.t
|
| 14 |
+
t/20_tie.t
|
| 15 |
+
t/22_stat_tie.t
|
| 16 |
+
t/24_watch_tie.t
|
| 17 |
+
t/30_connect.t
|
| 18 |
+
t/35_log.t
|
| 19 |
+
t/40_basic.t
|
| 20 |
+
t/45_class.t
|
| 21 |
+
t/50_access.t
|
| 22 |
+
t/60_watch.t
|
| 23 |
+
t/util.pl
|
local-test-zookeeper-full-01/afc-zookeeper/zookeeper-contrib/zookeeper-contrib-zkperl/Makefile.PL
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Net::ZooKeeper - Perl extension for Apache ZooKeeper
|
| 2 |
+
#
|
| 3 |
+
# Licensed to the Apache Software Foundation (ASF) under one
|
| 4 |
+
# or more contributor license agreements. See the NOTICE file
|
| 5 |
+
# distributed with this work for additional information
|
| 6 |
+
# regarding copyright ownership. The ASF licenses this file
|
| 7 |
+
# to you under the Apache License, Version 2.0 (the
|
| 8 |
+
# "License"); you may not use this file except in compliance
|
| 9 |
+
# with the License. You may obtain a copy of the License at
|
| 10 |
+
#
|
| 11 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 12 |
+
#
|
| 13 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 14 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 15 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 16 |
+
# See the License for the specific language governing permissions and
|
| 17 |
+
# limitations under the License.
|
| 18 |
+
|
| 19 |
+
use 5.008_008;
|
| 20 |
+
|
| 21 |
+
use Config;
|
| 22 |
+
use ExtUtils::MakeMaker;
|
| 23 |
+
use Getopt::Long;
|
| 24 |
+
|
| 25 |
+
my $ZOO_MAJOR_VERSION = 3;
|
| 26 |
+
my $ZOO_REQUIRED_VERSION = qr{^$ZOO_MAJOR_VERSION\.\d+.\d+$}ismx;
|
| 27 |
+
|
| 28 |
+
my @zk_inc_paths;
|
| 29 |
+
my @zk_lib_paths;
|
| 30 |
+
|
| 31 |
+
my $with_sasl2 = 0;
|
| 32 |
+
my @sasl2_inc_paths;
|
| 33 |
+
my @sasl2_lib_paths;
|
| 34 |
+
|
| 35 |
+
GetOptions(
|
| 36 |
+
'zookeeper-include=s' => \@zk_inc_paths,
|
| 37 |
+
'zookeeper-lib=s' => \@zk_lib_paths,
|
| 38 |
+
'with-sasl2!' => \$with_sasl2,
|
| 39 |
+
'sasl2-include=s' => \@sasl2_inc_paths,
|
| 40 |
+
'sasl2-lib=s' => \@sasl2_lib_paths
|
| 41 |
+
);
|
| 42 |
+
|
| 43 |
+
my $zk_inc = (join(' ', map("-I$_", @zk_inc_paths)) . ' -I.');
|
| 44 |
+
my $zk_libs = (join(' ', map("-L$_", @zk_lib_paths)) . ' -lzookeeper_mt');
|
| 45 |
+
|
| 46 |
+
my $cc = $Config{'cc'};
|
| 47 |
+
my $check_file = 'build/check_zk_version';
|
| 48 |
+
|
| 49 |
+
my $check_out = qx($cc $zk_inc -o $check_file $check_file.c $zk_libs 2>&1);
|
| 50 |
+
|
| 51 |
+
if ($?) {
|
| 52 |
+
if ($check_out =~ /zookeeper_version\.h/) {
|
| 53 |
+
die("Could not determine ZooKeeper version:\n\n$check_out");
|
| 54 |
+
}
|
| 55 |
+
else {
|
| 56 |
+
## keep in sync with build/check_zk_version.h
|
| 57 |
+
die("Net::ZooKeeper requires at least ZooKeeper version 3.1.1\n");
|
| 58 |
+
}
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
chomp(my $zk_ver = qx($check_file));
|
| 62 |
+
|
| 63 |
+
if ($? >> 8 != 0) {
|
| 64 |
+
die "Couldn't check zookeeper version: $zk_ver: $r";
|
| 65 |
+
}
|
| 66 |
+
elsif ($zk_ver !~ $ZOO_REQUIRED_VERSION) {
|
| 67 |
+
warn "Net::ZooKeeper requires ZooKeeper 3.x, found $zk_ver!";
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
my @inc = ($zk_inc);
|
| 71 |
+
my @libs = ($zk_libs);
|
| 72 |
+
my %mmopt = ();
|
| 73 |
+
|
| 74 |
+
if ($with_sasl2) {
|
| 75 |
+
push(@inc, join(' ', map("-I$_", @sasl2_inc_paths)));
|
| 76 |
+
push(@libs, join(' ', map("-L$_", @sasl2_lib_paths)) . ' -lsasl2');
|
| 77 |
+
$mmopt{DEFINE} = '-DHAVE_CYRUS_SASL_H';
|
| 78 |
+
}
|
| 79 |
+
|
| 80 |
+
WriteMakefile(
|
| 81 |
+
'INC' => join(' ', @inc),
|
| 82 |
+
'LIBS' => \@libs,
|
| 83 |
+
'NAME' => 'Net::ZooKeeper',
|
| 84 |
+
'VERSION_FROM' => 'ZooKeeper.pm',
|
| 85 |
+
'clean' => { 'FILES' => 'build/check_zk_version.o' },
|
| 86 |
+
%mmopt,
|
| 87 |
+
);
|
local-test-zookeeper-full-01/afc-zookeeper/zookeeper-contrib/zookeeper-contrib-zkperl/NOTICE
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Net::ZooKeeper - Perl extension for Apache ZooKeeper
|
| 2 |
+
Copyright 2009 The Apache Software Foundation
|
| 3 |
+
|
| 4 |
+
This product includes software developed at
|
| 5 |
+
The Apache Software Foundation (http://www.apache.org/).
|
| 6 |
+
|
local-test-zookeeper-full-01/afc-zookeeper/zookeeper-contrib/zookeeper-contrib-zkperl/ZooKeeper.pm
ADDED
|
@@ -0,0 +1,1285 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Net::ZooKeeper - Perl extension for Apache ZooKeeper
|
| 2 |
+
#
|
| 3 |
+
# Licensed to the Apache Software Foundation (ASF) under one
|
| 4 |
+
# or more contributor license agreements. See the NOTICE file
|
| 5 |
+
# distributed with this work for additional information
|
| 6 |
+
# regarding copyright ownership. The ASF licenses this file
|
| 7 |
+
# to you under the Apache License, Version 2.0 (the
|
| 8 |
+
# "License"); you may not use this file except in compliance
|
| 9 |
+
# with the License. You may obtain a copy of the License at
|
| 10 |
+
#
|
| 11 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 12 |
+
#
|
| 13 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 14 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 15 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 16 |
+
# See the License for the specific language governing permissions and
|
| 17 |
+
# limitations under the License.
|
| 18 |
+
|
| 19 |
+
use 5.008_008;
|
| 20 |
+
|
| 21 |
+
use strict;
|
| 22 |
+
use warnings;
|
| 23 |
+
|
| 24 |
+
package Net::ZooKeeper;
|
| 25 |
+
|
| 26 |
+
require Exporter;
|
| 27 |
+
require XSLoader;
|
| 28 |
+
|
| 29 |
+
our $VERSION = '0.36';
|
| 30 |
+
|
| 31 |
+
our @ISA = qw(Exporter);
|
| 32 |
+
|
| 33 |
+
our %EXPORT_TAGS = (
|
| 34 |
+
'errors' => [qw(
|
| 35 |
+
ZOK
|
| 36 |
+
ZSYSTEMERROR
|
| 37 |
+
ZRUNTIMEINCONSISTENCY
|
| 38 |
+
ZDATAINCONSISTENCY
|
| 39 |
+
ZCONNECTIONLOSS
|
| 40 |
+
ZMARSHALLINGERROR
|
| 41 |
+
ZUNIMPLEMENTED
|
| 42 |
+
ZOPERATIONTIMEOUT
|
| 43 |
+
ZBADARGUMENTS
|
| 44 |
+
ZINVALIDSTATE
|
| 45 |
+
ZAPIERROR
|
| 46 |
+
ZNONODE
|
| 47 |
+
ZNOAUTH
|
| 48 |
+
ZBADVERSION
|
| 49 |
+
ZNOCHILDRENFOREPHEMERALS
|
| 50 |
+
ZNODEEXISTS
|
| 51 |
+
ZNOTEMPTY
|
| 52 |
+
ZSESSIONEXPIRED
|
| 53 |
+
ZINVALIDCALLBACK
|
| 54 |
+
ZINVALIDACL
|
| 55 |
+
ZAUTHFAILED
|
| 56 |
+
ZCLOSING
|
| 57 |
+
ZNOTHING
|
| 58 |
+
)],
|
| 59 |
+
'node_flags' => [qw(
|
| 60 |
+
ZOO_EPHEMERAL
|
| 61 |
+
ZOO_SEQUENCE
|
| 62 |
+
)],
|
| 63 |
+
'acl_perms' => [qw(
|
| 64 |
+
ZOO_PERM_READ
|
| 65 |
+
ZOO_PERM_WRITE
|
| 66 |
+
ZOO_PERM_CREATE
|
| 67 |
+
ZOO_PERM_DELETE
|
| 68 |
+
ZOO_PERM_ADMIN
|
| 69 |
+
ZOO_PERM_ALL
|
| 70 |
+
)],
|
| 71 |
+
'acls' => [qw(
|
| 72 |
+
ZOO_OPEN_ACL_UNSAFE
|
| 73 |
+
ZOO_READ_ACL_UNSAFE
|
| 74 |
+
ZOO_CREATOR_ALL_ACL
|
| 75 |
+
)],
|
| 76 |
+
'events' => [qw(
|
| 77 |
+
ZOO_CREATED_EVENT
|
| 78 |
+
ZOO_DELETED_EVENT
|
| 79 |
+
ZOO_CHANGED_EVENT
|
| 80 |
+
ZOO_CHILD_EVENT
|
| 81 |
+
ZOO_SESSION_EVENT
|
| 82 |
+
ZOO_NOTWATCHING_EVENT
|
| 83 |
+
)],
|
| 84 |
+
'states' => [qw(
|
| 85 |
+
ZOO_EXPIRED_SESSION_STATE
|
| 86 |
+
ZOO_AUTH_FAILED_STATE
|
| 87 |
+
ZOO_CONNECTING_STATE
|
| 88 |
+
ZOO_ASSOCIATING_STATE
|
| 89 |
+
ZOO_CONNECTED_STATE
|
| 90 |
+
)],
|
| 91 |
+
'log_levels' => [qw(
|
| 92 |
+
ZOO_LOG_LEVEL_OFF
|
| 93 |
+
ZOO_LOG_LEVEL_ERROR
|
| 94 |
+
ZOO_LOG_LEVEL_WARN
|
| 95 |
+
ZOO_LOG_LEVEL_INFO
|
| 96 |
+
ZOO_LOG_LEVEL_DEBUG
|
| 97 |
+
)]
|
| 98 |
+
);
|
| 99 |
+
|
| 100 |
+
{
|
| 101 |
+
my %tags;
|
| 102 |
+
|
| 103 |
+
push @{$EXPORT_TAGS{'all'}},
|
| 104 |
+
grep {!$tags{$_}++} @{$EXPORT_TAGS{$_}} foreach (keys(%EXPORT_TAGS));
|
| 105 |
+
}
|
| 106 |
+
|
| 107 |
+
our @EXPORT_OK = ( @{$EXPORT_TAGS{'all'}} );
|
| 108 |
+
|
| 109 |
+
XSLoader::load('Net::ZooKeeper', $VERSION);
|
| 110 |
+
|
| 111 |
+
1;
|
| 112 |
+
|
| 113 |
+
__END__
|
| 114 |
+
|
| 115 |
+
=head1 NAME
|
| 116 |
+
|
| 117 |
+
Net::ZooKeeper - Perl extension for Apache ZooKeeper
|
| 118 |
+
|
| 119 |
+
=head1 SYNOPSIS
|
| 120 |
+
|
| 121 |
+
use Net::ZooKeeper qw(:node_flags :acls);
|
| 122 |
+
|
| 123 |
+
my $zkh = Net::ZooKeeper->new('localhost:7000');
|
| 124 |
+
|
| 125 |
+
$zkh->create('/foo', 'bar',
|
| 126 |
+
'flags' => ZOO_EPHEMERAL,
|
| 127 |
+
'acl' => ZOO_OPEN_ACL_UNSAFE) or
|
| 128 |
+
die("unable to create node /foo: " . $zkh->get_error() . "\n");
|
| 129 |
+
|
| 130 |
+
print "node /foo has value: " . $zkh->get('/foo') . "\n";
|
| 131 |
+
|
| 132 |
+
$zkh->set('/foo', 'baz');
|
| 133 |
+
|
| 134 |
+
print "node / has child nodes:\n";
|
| 135 |
+
foreach my $path ($zkh->get_children('/')) {
|
| 136 |
+
print " /$path\n";
|
| 137 |
+
}
|
| 138 |
+
|
| 139 |
+
my $stat = $zkh->stat();
|
| 140 |
+
if ($zkh->exists('/foo', 'stat' => $stat)) {
|
| 141 |
+
print "node /foo has stat info:\n";
|
| 142 |
+
while (my($key,$value) = each(%{$stat})) {
|
| 143 |
+
print " $key: $value\n";
|
| 144 |
+
}
|
| 145 |
+
}
|
| 146 |
+
|
| 147 |
+
foreach my $acl_entry ($zkh->get_acl('/foo')) {
|
| 148 |
+
print "node /foo has ACL entry:\n";
|
| 149 |
+
print " perms: $acl_entry->{perms}\n";
|
| 150 |
+
print " scheme: $acl_entry->{scheme}\n";
|
| 151 |
+
print " id: $acl_entry->{id}\n";
|
| 152 |
+
}
|
| 153 |
+
|
| 154 |
+
my $watch = $zkh->watch('timeout' => 10000);
|
| 155 |
+
$zkh->exists('/foo', 'watch' => $watch);
|
| 156 |
+
|
| 157 |
+
if ($watch->wait()) {
|
| 158 |
+
print "watch triggered on node /foo:\n";
|
| 159 |
+
print " event: $watch->{event}\n";
|
| 160 |
+
print " state: $watch->{state}\n";
|
| 161 |
+
}
|
| 162 |
+
else {
|
| 163 |
+
print "watch timed out after 10 seconds\n";
|
| 164 |
+
}
|
| 165 |
+
|
| 166 |
+
$zkh->delete('/foo');
|
| 167 |
+
|
| 168 |
+
=head1 DESCRIPTION
|
| 169 |
+
|
| 170 |
+
Net::ZooKeeper provides a Perl interface to the synchronous C API
|
| 171 |
+
of Apache ZooKeeper. ZooKeeper is coordination service for
|
| 172 |
+
distributed applications.
|
| 173 |
+
|
| 174 |
+
Each connection to ZooKeeper is represented as a handle object
|
| 175 |
+
of the class Net::ZooKeeper, similar to the manner in which database
|
| 176 |
+
connections are represented in the DBI module.
|
| 177 |
+
|
| 178 |
+
To disconnect from ZooKeeper, simply destroy the Net::ZooKeeper
|
| 179 |
+
handle object by undefining it or by explicitly calling the
|
| 180 |
+
C<DESTROY()> method.
|
| 181 |
+
|
| 182 |
+
The methods which may be invoked on Net::ZooKeeper handles
|
| 183 |
+
correspond to the functions of the synchronous ZooKeeper C API;
|
| 184 |
+
e.g., the Net::ZooKeeper method C<create()> calls the ZooKeeper
|
| 185 |
+
C function C<zoo_create()>, C<delete()> calls C<zoo_delete()>,
|
| 186 |
+
and so forth.
|
| 187 |
+
|
| 188 |
+
The synchronous API functions wait for a response from the ZooKeeper
|
| 189 |
+
cluster before returning a result to the caller. Using these
|
| 190 |
+
functions permits Net::ZooKeeper to provide an interface similar
|
| 191 |
+
to that of a DBI driver module.
|
| 192 |
+
|
| 193 |
+
=head2 Internal POSIX Threads
|
| 194 |
+
|
| 195 |
+
The use of the synchronous ZooKeeper C API still requires that
|
| 196 |
+
the ZooKeeper C client code create several POSIX threads which run
|
| 197 |
+
concurrently with the main thread containing the Perl interpreter.
|
| 198 |
+
|
| 199 |
+
The synchronous API functions are wrappers of the asynchronous
|
| 200 |
+
functions in the ZooKeeper C API. When a request is made by the
|
| 201 |
+
caller's thread (i.e., the one with the running Perl interpreter),
|
| 202 |
+
it is enqueued for delivery at a later time by the ZooKeeper C client
|
| 203 |
+
code's IO thread. The caller's thread then waits for notification
|
| 204 |
+
before returning from the synchronous API function.
|
| 205 |
+
|
| 206 |
+
The IO thread dequeues the request and sends it to the ZooKeeper
|
| 207 |
+
cluster, while also ensuring that a regular "heartbeat" is maintained
|
| 208 |
+
with the cluster so that the current session does not time out.
|
| 209 |
+
When the IO thread receives a response from
|
| 210 |
+
the ZooKeeper cluster, it enqueues the response for delivery to the
|
| 211 |
+
client by the second thread of the ZooKeeper client code, the
|
| 212 |
+
completion thread.
|
| 213 |
+
|
| 214 |
+
If the caller is using the asynchronous API, the completion thread
|
| 215 |
+
invokes the appropriate callback function provided by the caller
|
| 216 |
+
for the given request. In the case of Net::ZooKeeper, it is not
|
| 217 |
+
viable for the completion thread to invoke a Perl callback function
|
| 218 |
+
at arbitrary times; this could interfere with the state of the
|
| 219 |
+
Perl interpreter.
|
| 220 |
+
|
| 221 |
+
For this reason Net::ZooKeeper uses the synchronous API only. After
|
| 222 |
+
enqueuing requests the synchronous API functions wait for notification
|
| 223 |
+
of the corresponding response. The completion thread delivers these
|
| 224 |
+
notifications, at which point the synchronous functions return to
|
| 225 |
+
their caller.
|
| 226 |
+
|
| 227 |
+
Note that the IO and completion threads are POSIX threads, not
|
| 228 |
+
Perl ithreads. Net::ZooKeeper defined a C<CLONE_SKIP()> function so
|
| 229 |
+
that if Perl ithreads are spawned while a Net::ZooKeeper connection
|
| 230 |
+
is active, the Net::ZooKeeper handle objects inherited by the
|
| 231 |
+
spawned ithread contain undefined values so that they can not be used.
|
| 232 |
+
Thus each ithread will need to create its own private connections to a
|
| 233 |
+
ZooKeeper cluster.
|
| 234 |
+
|
| 235 |
+
Note also that before invoking C<fork()> to spawn a new process,
|
| 236 |
+
all Net::ZooKeeper handles should be destroyed so that all
|
| 237 |
+
connections to ZooKeeper are closed and all internal POSIX threads
|
| 238 |
+
have exited. If a child process needs to communicate with
|
| 239 |
+
ZooKeeper it should open its own private connections after it is
|
| 240 |
+
created by C<fork()>.
|
| 241 |
+
|
| 242 |
+
=head2 Signals
|
| 243 |
+
|
| 244 |
+
The ZooKeeper C API uses TCP connections to communicate with
|
| 245 |
+
the ZooKeeper cluster. These connections may generate SIGPIPE
|
| 246 |
+
signals when they encounter errors, such as when a connection
|
| 247 |
+
is terminated by a ZooKeeper server. Therefore most applications
|
| 248 |
+
will want to trap or ignore SIGPIPE signals, e.g.:
|
| 249 |
+
|
| 250 |
+
local $SIG{'PIPE'} = 'IGNORE';
|
| 251 |
+
|
| 252 |
+
Ignoring SIGPIPE signals (or providing a signal handler that returns
|
| 253 |
+
control to the interrupted program after receiving the signal)
|
| 254 |
+
will allow the ZooKeeper C client code to detect the connection error
|
| 255 |
+
and report it upon return from the next Net::ZooKeeper method.
|
| 256 |
+
|
| 257 |
+
=head2 Error Handling
|
| 258 |
+
|
| 259 |
+
Net::ZooKeeper methods return different values in the case of an
|
| 260 |
+
error depending on their purpose and context. For example,
|
| 261 |
+
C<exists()> returns true if the node exists and false otherwise,
|
| 262 |
+
which may indicate either that the node does not exist or that
|
| 263 |
+
an error occurred.
|
| 264 |
+
|
| 265 |
+
After any method returns a false, empty, or undefined value which
|
| 266 |
+
might indicate an error has occurred, the C<get_error()> method
|
| 267 |
+
may be called to examine the specific error code, if any.
|
| 268 |
+
|
| 269 |
+
If C<get_error()> returns C<ZOK>, no error has occurred. If the
|
| 270 |
+
error code is less than C<ZAPIERROR>, it indicates a normal error
|
| 271 |
+
condition reported by the ZooKeeper server, such as C<ZNONODE>
|
| 272 |
+
(node does not exist) or C<ZNODEEXISTS> (node already exists).
|
| 273 |
+
|
| 274 |
+
If the error code is greater than C<ZAPIERROR>, then a connection
|
| 275 |
+
error or server error has occurred and the client should probably
|
| 276 |
+
close the connection by undefining the Net::ZooKeeper handle object
|
| 277 |
+
and, if necessary, attempt to create a new connection to the
|
| 278 |
+
ZooKeeper cluster.
|
| 279 |
+
|
| 280 |
+
=head2 Access Control
|
| 281 |
+
|
| 282 |
+
If the ZooKeeper cluster is not configured with C<skipACL=yes> then
|
| 283 |
+
it will respect the access controls set for each node in the
|
| 284 |
+
ZooKeeper hierarchy. These access controls are defined using ACLs
|
| 285 |
+
(Access Control Lists); see the ZooKeeper documentation for compete
|
| 286 |
+
details.
|
| 287 |
+
|
| 288 |
+
In Net::ZooKeeper, ACLs are represented as arrays of hashes, where
|
| 289 |
+
each hash is an ACL entry that must contain three attributes,
|
| 290 |
+
C<perms>, C<scheme>, and C<id>. The C<perms> attribute's value
|
| 291 |
+
should be composed by combining ACL permission flags using the
|
| 292 |
+
bitwise OR operator. See C<:acl_perms> for a list of the
|
| 293 |
+
available ACL permission flags.
|
| 294 |
+
|
| 295 |
+
The ACL for a node may be read using the C<get_acl()> method. A
|
| 296 |
+
node's ACL may be set when the node is created by passing an ACL
|
| 297 |
+
array as the value of the C<'acl'> option to the C<create()> method,
|
| 298 |
+
and may be updated by passing an ACL array to the C<set_acl()> method.
|
| 299 |
+
|
| 300 |
+
When a client connects to a ZooKeeper cluster it is automatically
|
| 301 |
+
assigned authentication credentials based on its IP address.
|
| 302 |
+
Additional authentication credentials may be added using
|
| 303 |
+
the C<add_auth()> method. Once a credential has been added for
|
| 304 |
+
the current session, there is no way to disable it.
|
| 305 |
+
|
| 306 |
+
As an example, digest authentication may be enabled for a session
|
| 307 |
+
by calling C<add_auth()> as follows:
|
| 308 |
+
|
| 309 |
+
$zkh->add_auth('digest', "$username:$password");
|
| 310 |
+
|
| 311 |
+
Note that the username and password are transmitted in cleartext
|
| 312 |
+
to the ZooKeeper cluster.
|
| 313 |
+
|
| 314 |
+
Such authentication credentials would enable access to a node
|
| 315 |
+
whose ACL contained an entry with a C<scheme> attribute of
|
| 316 |
+
C<'digest'> and an C<id> attribute containing a Base64-encoded
|
| 317 |
+
SHA1 digest of the string C<"$username:$password">. The
|
| 318 |
+
Perl modules Digest and MIME::Base64 may be used to create
|
| 319 |
+
such ACL ID values as follows:
|
| 320 |
+
|
| 321 |
+
use Digest qw();
|
| 322 |
+
use MIME::Base64 qw();
|
| 323 |
+
|
| 324 |
+
my $ctx = Digest->new('SHA-1')->add("$username:$password");
|
| 325 |
+
my $digest = MIME::Base64::encode($ctx->digest());
|
| 326 |
+
|
| 327 |
+
Note that using the C<b64digest()> method of the Digest module
|
| 328 |
+
will not result in digest strings with the "=" suffix characters
|
| 329 |
+
required by ZooKeeper.
|
| 330 |
+
|
| 331 |
+
=head2 Logging
|
| 332 |
+
|
| 333 |
+
As of ZooKeeper version 3.1.1, logging in the C client code is
|
| 334 |
+
implemented with a single, shared file handle to which all
|
| 335 |
+
of the internal POSIX threads write log messages; by default,
|
| 336 |
+
this file handle is attached to STDERR.
|
| 337 |
+
|
| 338 |
+
Moreover, this file handle is shared by all active ZooKeeper
|
| 339 |
+
connections (each of which has its own private IO and completion
|
| 340 |
+
threads; see L</Internal POSIX Threads> above).
|
| 341 |
+
|
| 342 |
+
Net::ZooKeeper therefore does not provide per-connection handle
|
| 343 |
+
attributes related to logging. The global function
|
| 344 |
+
C<Net::ZooKeeper::set_log_level()> may be used to set the current
|
| 345 |
+
log level. See C<:log_levels> for a list of the available log
|
| 346 |
+
levels. The default log level is C<ZOO_LOG_LEVEL_OFF>.
|
| 347 |
+
|
| 348 |
+
To capture ZooKeeper log messages to a file instead of STDERR,
|
| 349 |
+
redirect STDERR to a new file handle in the normal Perl manner:
|
| 350 |
+
|
| 351 |
+
open(OLDERR, '>&', fileno(STDERR)) or
|
| 352 |
+
die("unable to dup STDERR: $!");
|
| 353 |
+
open(STDERR, '>', $log_file) or
|
| 354 |
+
die("unable to redirect STDERR: $!");
|
| 355 |
+
|
| 356 |
+
=head2 Connection Order
|
| 357 |
+
|
| 358 |
+
ZooKeeper clusters are typically made up of an odd number of
|
| 359 |
+
ZooKeeper servers. When connecting to such a cluster, the
|
| 360 |
+
C<new()> method should be passed a comma-separated list of
|
| 361 |
+
the hostnames and ports for each of the servers in the cluster,
|
| 362 |
+
e.g., C<'host1:7000,host2:7000,host2:7100'>.
|
| 363 |
+
|
| 364 |
+
The default behaviour of the ZooKeeper client code is to
|
| 365 |
+
reorder this list randomly before making any connections.
|
| 366 |
+
A connection is then made to the first server in the reordered
|
| 367 |
+
list. If that connection fails, the IO thread will
|
| 368 |
+
automatically attempt to reconnect to the cluster, this time
|
| 369 |
+
to the next server in the list; when the last server in the list
|
| 370 |
+
is reached, the IO thread will continue again with the first
|
| 371 |
+
server.
|
| 372 |
+
|
| 373 |
+
For certain purposes it may be necessary for ZooKeeper clients
|
| 374 |
+
to know the exact order in which the IO thread will attempt to
|
| 375 |
+
connect to the servers of a cluster. To do so, call
|
| 376 |
+
C<Net::ZooKeeper::set_deterministic_conn_order(1)>. Note,
|
| 377 |
+
however, that this will affect all Net::ZooKeeper object
|
| 378 |
+
handles created by the current process.
|
| 379 |
+
|
| 380 |
+
=head1 ATTRIBUTES
|
| 381 |
+
|
| 382 |
+
=head2 Net::ZooKeeper
|
| 383 |
+
|
| 384 |
+
The Net::ZooKeeper class provides the main interface to the
|
| 385 |
+
ZooKeeper client API. The following attributes are available
|
| 386 |
+
for each Net::ZooKeeper handle object and are specific to
|
| 387 |
+
that handle and the method calls invoked on it. As with DBI
|
| 388 |
+
handle objects, attributes may be read and written through
|
| 389 |
+
a hash interface, e.g.:
|
| 390 |
+
|
| 391 |
+
print sprintf("Session timeout is %.2f seconds.\n",
|
| 392 |
+
$zkh->{session_timeout} / 1000);
|
| 393 |
+
|
| 394 |
+
$zkh->{watch_timeout} = 10000;
|
| 395 |
+
|
| 396 |
+
=over 4
|
| 397 |
+
|
| 398 |
+
=item hosts
|
| 399 |
+
|
| 400 |
+
The comma-separated list of ZooKeeper server hostnames and ports
|
| 401 |
+
as passed to the C<new()> method. Note that by default the
|
| 402 |
+
ZooKeeper C client code will reorder this list before attempting
|
| 403 |
+
to connect for the first time; see L</Connection Order> for details.
|
| 404 |
+
|
| 405 |
+
This attribute is B<read-only> and may not be modified.
|
| 406 |
+
|
| 407 |
+
=item session_timeout
|
| 408 |
+
|
| 409 |
+
The session timeout value, in milliseconds, as set by the
|
| 410 |
+
ZooKeeper server after connection. This value may not be
|
| 411 |
+
exactly the same as what was requested in the C<'session_timeout'>
|
| 412 |
+
option of the C<new()> method; the server will adjust the
|
| 413 |
+
requested timeout value so that it is within a certain range
|
| 414 |
+
of the server's C<tickTime> setting. See the ZooKeeper
|
| 415 |
+
documentation for details.
|
| 416 |
+
|
| 417 |
+
Because the actual connection to the ZooKeeper server is
|
| 418 |
+
not made during the C<new()> method call but shortly
|
| 419 |
+
thereafter by the IO thread, note that this value may not
|
| 420 |
+
be initialized to its final value until at least one
|
| 421 |
+
other method which requires communication with the server
|
| 422 |
+
(such as C<exists()>) has succeeded.
|
| 423 |
+
|
| 424 |
+
This attribute is B<read-only> and may not be modified.
|
| 425 |
+
|
| 426 |
+
=item session_id
|
| 427 |
+
|
| 428 |
+
The client's session ID value as set by the ZooKeeper server
|
| 429 |
+
after connection. This is a binary data string which may
|
| 430 |
+
be passed to subsequent C<new()> calls as the value of
|
| 431 |
+
the C<'session_id'> option, if the user wishes to attempt to
|
| 432 |
+
continue a session after a failure. Note that the server
|
| 433 |
+
may not honour such an attempt.
|
| 434 |
+
|
| 435 |
+
Because the actual connection to the ZooKeeper server is
|
| 436 |
+
not made during the C<new()> method call but shortly
|
| 437 |
+
thereafter by the IO thread, note that this value may not
|
| 438 |
+
be initialized to its final value until at least one
|
| 439 |
+
other method which requires communication with the server
|
| 440 |
+
(such as C<exists()>) has succeeded.
|
| 441 |
+
|
| 442 |
+
This attribute is B<read-only> and may not be modified.
|
| 443 |
+
|
| 444 |
+
=item data_read_len
|
| 445 |
+
|
| 446 |
+
The maximum length of node data that will be returned to
|
| 447 |
+
the caller by the C<get()> method. If a node's data exceeds
|
| 448 |
+
this length, the returned value will be shorter than the
|
| 449 |
+
actual node data as stored in the ZooKeeper cluster.
|
| 450 |
+
|
| 451 |
+
The default maximum length of the node data returned by
|
| 452 |
+
C<get()> is 1023 bytes. This may be changed by setting
|
| 453 |
+
the C<data_read_len> attribute to a different value.
|
| 454 |
+
|
| 455 |
+
Passing a value for the C<'data_read_len'> option when calling
|
| 456 |
+
the C<get()> method will temporarily override the per-handle
|
| 457 |
+
maximum.
|
| 458 |
+
|
| 459 |
+
=item path_read_len
|
| 460 |
+
|
| 461 |
+
The maximum length of a newly created node's path that will
|
| 462 |
+
be returned to the caller by the C<create()> method. If the path
|
| 463 |
+
of the newly created node exceeds this length, the returned
|
| 464 |
+
value will be shorter than the actual path of the node as stored
|
| 465 |
+
in the ZooKeeper cluster.
|
| 466 |
+
|
| 467 |
+
The default maximum length of the node path returned by
|
| 468 |
+
C<create()> is 1023 bytes. This may be changed by setting
|
| 469 |
+
the C<path_read_len> attribute to a different value.
|
| 470 |
+
|
| 471 |
+
Passing a value for the C<'path_read_len'> option when calling
|
| 472 |
+
the C<create()> method will temporarily override the current
|
| 473 |
+
value of this attribute.
|
| 474 |
+
|
| 475 |
+
=item watch_timeout
|
| 476 |
+
|
| 477 |
+
The C<timeout> attribute value, in milliseconds, inherited by
|
| 478 |
+
all watch objects (of class Net::ZooKeeper::Watch) created by
|
| 479 |
+
calls to the C<watch()> method. When a watch object's
|
| 480 |
+
C<wait()> method is invoked without a C<'timeout'> option,
|
| 481 |
+
it waits for an event notification from the ZooKeeper cluster
|
| 482 |
+
for no longer than the timeout period specified by the value of
|
| 483 |
+
the watch object's C<timeout> attribute.
|
| 484 |
+
|
| 485 |
+
The default C<timeout> attribute value for all watch objects
|
| 486 |
+
created by the C<watch()> method is 1 minute (60000
|
| 487 |
+
milliseconds). This may be changed for a particular handle
|
| 488 |
+
object by setting this attribute to a different value; afterwards,
|
| 489 |
+
the new value will be inherited by any watch objects created
|
| 490 |
+
by the handle object's C<watch()> method. Previously
|
| 491 |
+
created watch objects will not be affected.
|
| 492 |
+
|
| 493 |
+
Passing a value for the C<'timeout'> option when calling
|
| 494 |
+
the C<watch()> method will temporarily override the current
|
| 495 |
+
value of this attribute and cause the newly created watch object
|
| 496 |
+
to inherit a different value.
|
| 497 |
+
|
| 498 |
+
See also the C<watch()> method, and the C<timeout> attribute
|
| 499 |
+
and C<wait()> method of the Net::ZooKeeper::Watch class.
|
| 500 |
+
|
| 501 |
+
=item pending_watches
|
| 502 |
+
|
| 503 |
+
The number of internal ZooKeeper watches created for this handle
|
| 504 |
+
object that are still awaiting an event notification from the
|
| 505 |
+
ZooKeeper cluster.
|
| 506 |
+
|
| 507 |
+
Note that this number may be different than the number of
|
| 508 |
+
extant watch objects created by the handle object's C<watch()>
|
| 509 |
+
method, not only because some event notifications may have
|
| 510 |
+
occurred, but also if any watch objects have been reassigned
|
| 511 |
+
by reusing them in more than one call to any of the C<exists()>,
|
| 512 |
+
C<get_children()>, or C<get()> methods.
|
| 513 |
+
|
| 514 |
+
This attribute is B<read-only> and may not be modified.
|
| 515 |
+
|
| 516 |
+
=back
|
| 517 |
+
|
| 518 |
+
=head2 Net::ZooKeeper::Stat
|
| 519 |
+
|
| 520 |
+
The Net::ZooKeeper::Stat class provides a hash interface to
|
| 521 |
+
the individual pieces of information which together compose the
|
| 522 |
+
state of a given ZooKeeper node. Net::ZooKeeper::Stat objects
|
| 523 |
+
are created by calling the C<stat()> method on a Net::ZooKeeper
|
| 524 |
+
handle object, and may then be passed to any methods which accept
|
| 525 |
+
a C<'stat'> option value, such as C<exists()>.
|
| 526 |
+
|
| 527 |
+
Net::ZooKeeper::Stat objects may be reused multiple times.
|
| 528 |
+
If the Net::ZooKeeper method to which the stat object is
|
| 529 |
+
passed succeeds, then the stat object is updated with the newly
|
| 530 |
+
retrieved node state information, and any state information
|
| 531 |
+
previously stored in the stat object is overwritten.
|
| 532 |
+
|
| 533 |
+
All of the attributes of stat objects are B<read-only>.
|
| 534 |
+
|
| 535 |
+
=over 4
|
| 536 |
+
|
| 537 |
+
=item ctime
|
| 538 |
+
|
| 539 |
+
The creation time of the node in milliseconds since the epoch.
|
| 540 |
+
|
| 541 |
+
=item mtime
|
| 542 |
+
|
| 543 |
+
The time of the last modification of the node's data in
|
| 544 |
+
milliseconds since the epoch.
|
| 545 |
+
|
| 546 |
+
=item data_len
|
| 547 |
+
|
| 548 |
+
The length of the node's data in bytes.
|
| 549 |
+
|
| 550 |
+
=item num_children
|
| 551 |
+
|
| 552 |
+
The number of child nodes beneath of the current node.
|
| 553 |
+
|
| 554 |
+
=item ephemeral_owner
|
| 555 |
+
|
| 556 |
+
If the node was created with the C<ZOO_EPHEMERAL> flag,
|
| 557 |
+
this attribute holds the session ID of the ZooKeeper client
|
| 558 |
+
which created the node. If the node was not created with
|
| 559 |
+
the C<ZOO_EPHEMERAL> flag, this attribute is set to zero.
|
| 560 |
+
|
| 561 |
+
=item version
|
| 562 |
+
|
| 563 |
+
The number of revisions of the node's data. The ZooKeeper
|
| 564 |
+
cluster will increment this version number whenever the
|
| 565 |
+
node's data is changed. When the node is first created this
|
| 566 |
+
version number is initialized to zero.
|
| 567 |
+
|
| 568 |
+
=item acl_version
|
| 569 |
+
|
| 570 |
+
The number of revisions of the node's ACL. The ZooKeeper
|
| 571 |
+
cluster will increment this version number whenever the
|
| 572 |
+
node's ACL is changed. When the node is first created this
|
| 573 |
+
version number is initialized to zero.
|
| 574 |
+
|
| 575 |
+
=item children_version
|
| 576 |
+
|
| 577 |
+
The number of revisions of the node's list of child nodes.
|
| 578 |
+
The ZooKeeper cluster will increment this version number
|
| 579 |
+
whenever the list of child nodes is changed. When the node
|
| 580 |
+
is first created this version number is initialized to zero.
|
| 581 |
+
|
| 582 |
+
=item czxid
|
| 583 |
+
|
| 584 |
+
The ZooKeeper transaction ID (ZXID) of the transaction which
|
| 585 |
+
created the node.
|
| 586 |
+
|
| 587 |
+
=item mzxid
|
| 588 |
+
|
| 589 |
+
The ZooKeeper transaction ID (ZXID) of the transaction which
|
| 590 |
+
last modified the node's data. This is initially set to
|
| 591 |
+
the same transaction ID as the C<czxid> attribute by the
|
| 592 |
+
C<create()> method.
|
| 593 |
+
|
| 594 |
+
=item children_zxid
|
| 595 |
+
|
| 596 |
+
The ZooKeeper transaction ID (ZXID) of the transaction which
|
| 597 |
+
last modified the node's list of child nodes. This is
|
| 598 |
+
initially set to the same transaction ID as the C<czxid>
|
| 599 |
+
attribute by the C<create()> method.
|
| 600 |
+
|
| 601 |
+
=back
|
| 602 |
+
|
| 603 |
+
=head2 Net::ZooKeeper::Watch
|
| 604 |
+
|
| 605 |
+
The Net::ZooKeeper::Watch class provides a hash interface
|
| 606 |
+
to the data returned by event notifications from the ZooKeeper
|
| 607 |
+
cluster. Net::ZooKeeper::Watch objects are created by calling
|
| 608 |
+
the C<watch()> method on a Net::ZooKeeper handle object, and
|
| 609 |
+
may then be passed to any methods which accept a C<'watch'>
|
| 610 |
+
option value, such as C<exists()>.
|
| 611 |
+
|
| 612 |
+
Net::ZooKeeper::Watch objects may be reused multiple times.
|
| 613 |
+
Regardless of whether the Net::ZooKeeper method to which the
|
| 614 |
+
watch object is passed succeeds, the watch object will be
|
| 615 |
+
updated to receive an event notification exclusively for the
|
| 616 |
+
node referenced in that method call. In the case of an error,
|
| 617 |
+
however, the watch object may never receive any event
|
| 618 |
+
notification.
|
| 619 |
+
|
| 620 |
+
=over 4
|
| 621 |
+
|
| 622 |
+
=item timeout
|
| 623 |
+
|
| 624 |
+
The default timeout value, in milliseconds, for all
|
| 625 |
+
invocations of the C<wait()> method made on the watch object.
|
| 626 |
+
When the C<wait()> method is invoked without a
|
| 627 |
+
C<'timeout'> option value, it waits for an
|
| 628 |
+
event notification from the ZooKeeper cluster for no longer
|
| 629 |
+
than the timeout period specified by this attribute.
|
| 630 |
+
This default timeout period may be altered by setting this
|
| 631 |
+
attribute to a different value.
|
| 632 |
+
|
| 633 |
+
Passing a value for the C<'timeout'> option when calling
|
| 634 |
+
the C<wait()> method will temporarily override the current
|
| 635 |
+
value of this attribute and cause the C<wait()> method to
|
| 636 |
+
use a different timeout period.
|
| 637 |
+
|
| 638 |
+
When a Net::ZooKeeper handle object's C<watch()> method is
|
| 639 |
+
invoked without a C<'timeout'> option, it returns a newly
|
| 640 |
+
created watch object whose C<timeout> attribute value
|
| 641 |
+
is initialized to the current value of the handle object's
|
| 642 |
+
C<watch_timeout> attribute. When the C<watch()> method is invoked
|
| 643 |
+
with a C<'timeout'> option, the new watch object's C<timeout>
|
| 644 |
+
attribute value is initialized to the value specified by
|
| 645 |
+
the C<'timeout'> option.
|
| 646 |
+
|
| 647 |
+
See also the C<wait()> method, and the C<watch_timeout> attribute
|
| 648 |
+
and C<watch()> method of the Net::ZooKeeper class.
|
| 649 |
+
|
| 650 |
+
=item event
|
| 651 |
+
|
| 652 |
+
The type of event which triggered the notification, such
|
| 653 |
+
as C<ZOO_CHANGED_EVENT> if the node's data was changed.
|
| 654 |
+
See C<:events> for a list of the possible event types.
|
| 655 |
+
If zero, no event notification has occurred yet.
|
| 656 |
+
|
| 657 |
+
Note that the events which will trigger a notification
|
| 658 |
+
will depend on the Net::ZooKeeper method to which
|
| 659 |
+
the watch object was passed. Watches set through the
|
| 660 |
+
C<exists()> and C<get()> methods will report events relating
|
| 661 |
+
to the node's data, while watches set through the
|
| 662 |
+
C<get_children()> method will report events relating to the
|
| 663 |
+
creation or deletion of child nodes of the watched node.
|
| 664 |
+
|
| 665 |
+
This attribute is B<read-only> and may not be modified.
|
| 666 |
+
|
| 667 |
+
=item state
|
| 668 |
+
|
| 669 |
+
The state of the Net::ZooKeeper connection at the time of
|
| 670 |
+
the event notification. See C<:states> for a list of
|
| 671 |
+
the possible connection states. If zero, no event
|
| 672 |
+
notification has occurred yet.
|
| 673 |
+
|
| 674 |
+
This attribute is B<read-only> and may not be modified.
|
| 675 |
+
|
| 676 |
+
=back
|
| 677 |
+
|
| 678 |
+
=head1 METHODS
|
| 679 |
+
|
| 680 |
+
=head2 Net::ZooKeeper
|
| 681 |
+
|
| 682 |
+
The following methods are defined for the Net::ZooKeeper class.
|
| 683 |
+
|
| 684 |
+
=over 4
|
| 685 |
+
|
| 686 |
+
=item new()
|
| 687 |
+
|
| 688 |
+
$zkh = Net::ZooKeeper->new('host1:7000,host2:7000');
|
| 689 |
+
$zkh = Net::ZooKeeper->new('host1:7000,host2:7000',
|
| 690 |
+
'session_timeout' => $session_timeout,
|
| 691 |
+
'session_id' => $session_id,
|
| 692 |
+
'sasl_options' => $sasl_options);
|
| 693 |
+
|
| 694 |
+
Creates a new Net::ZooKeeper handle object and attempts to
|
| 695 |
+
connect to the one of the servers of the given ZooKeeper
|
| 696 |
+
cluster. As described in the L</Internal POSIX Threads> and
|
| 697 |
+
L</Connection Order> sections, the ZooKeeper client code will
|
| 698 |
+
create an IO thread which maintains the connection with a
|
| 699 |
+
regular "heartbeat" request. In the event of a connection error
|
| 700 |
+
the IO thread will also attempt to reconnect to another one of
|
| 701 |
+
the servers using the same session ID. In general, these actions
|
| 702 |
+
should be invisible to the user, although Net::ZooKeeper methods
|
| 703 |
+
may return transient errors while the IO thread
|
| 704 |
+
reconnects with another server.
|
| 705 |
+
|
| 706 |
+
To disconnect, undefine the Net::ZooKeeper handle object
|
| 707 |
+
or call the C<DESTROY()> method. (After calling C<DESTROY()>
|
| 708 |
+
the handle object can not be reused.)
|
| 709 |
+
|
| 710 |
+
The ZooKeeper client code will send a "heartbeat" message
|
| 711 |
+
if a third of the session timeout period has elapsed without
|
| 712 |
+
any communication with the ZooKeeper server. A specific
|
| 713 |
+
session timeout period may be requested when creating a
|
| 714 |
+
Net::ZooKeeper handle object by supplying a value, in
|
| 715 |
+
milliseconds, for the C<'session_timeout'> option. The
|
| 716 |
+
ZooKeeper server adjust the requested timeout value so that
|
| 717 |
+
it is within a certain range of the server's C<tickTime> setting;
|
| 718 |
+
the actual session timeout value will be available as the
|
| 719 |
+
value of the handle's C<session_timeout> attribute after at
|
| 720 |
+
least one method call has succeeded. See the C<session_timeout>
|
| 721 |
+
attribute for more information.
|
| 722 |
+
|
| 723 |
+
If no C<'session_timeout'> option is provided, the default
|
| 724 |
+
value of 10 seconds (10000 milliseconds) will be used in the
|
| 725 |
+
initial connection request; again, the actual timeout period to
|
| 726 |
+
which the server agrees will be available subsequently as the
|
| 727 |
+
value of the C<session_timeout> attribute.
|
| 728 |
+
|
| 729 |
+
If a C<'sasl_options'> option is provided, it is used to automatically
|
| 730 |
+
SASL-authenticate with the server during connections (including
|
| 731 |
+
reconnects). Here is a brief description of the recognized keys;
|
| 732 |
+
please refer to the C client documentation for details:
|
| 733 |
+
|
| 734 |
+
=over 5
|
| 735 |
+
|
| 736 |
+
=item service => VALUE
|
| 737 |
+
|
| 738 |
+
=item host => VALUE
|
| 739 |
+
|
| 740 |
+
=item mechlist => VALUE
|
| 741 |
+
|
| 742 |
+
These map to the corresponding fields of C<zoo_sasl_params_t> from the
|
| 743 |
+
library.
|
| 744 |
+
|
| 745 |
+
=item user => VALUE
|
| 746 |
+
|
| 747 |
+
=item realm => VALUE
|
| 748 |
+
|
| 749 |
+
=item password_file => VALUE
|
| 750 |
+
|
| 751 |
+
These map to the corresponding parameters of
|
| 752 |
+
C<zoo_sasl_make_basic_callbacks> from the library.
|
| 753 |
+
|
| 754 |
+
=back
|
| 755 |
+
|
| 756 |
+
Upon successful connection (i.e., after the success of a method
|
| 757 |
+
which requires communication with the server), the C<session_id>
|
| 758 |
+
attribute will hold a short binary string which represents the
|
| 759 |
+
client's session ID as set by the server. All ephemeral nodes
|
| 760 |
+
created by the session are identified by this ID in the
|
| 761 |
+
C<ephemeral_owner> attribute of any Net::ZooKeeper::Stat objects
|
| 762 |
+
used to query their state.
|
| 763 |
+
|
| 764 |
+
The ZooKeeper client code will use this session ID internally
|
| 765 |
+
whenever it tries to reconnect to another server in the ZooKeeper
|
| 766 |
+
cluster after detecting a failed connection. If it successfully
|
| 767 |
+
reconnects with the same session ID, the session will continue
|
| 768 |
+
and ephemeral nodes belonging to it will not be deleted.
|
| 769 |
+
|
| 770 |
+
However, if the server determines that the session has timed
|
| 771 |
+
out (for example because no "heartbeat" requests have been
|
| 772 |
+
received within the agreed-upon session timeout period), the
|
| 773 |
+
session will be terminated by the cluster and all ephemeral nodes
|
| 774 |
+
owned by the current session automatically deleted.
|
| 775 |
+
|
| 776 |
+
On occasion the ZooKeeper client code may not be able to quickly
|
| 777 |
+
reconnect to a live server and the caller may want to destroy
|
| 778 |
+
the existing Net::ZooKeeper handle object and attempt a
|
| 779 |
+
fresh connection using the same session ID as before with a
|
| 780 |
+
new Net::ZooKeeper object. To do so, save the C<session_id>
|
| 781 |
+
attribute value before undefining the old handle object
|
| 782 |
+
and then pass that binary string as the value of the
|
| 783 |
+
C<'session_id'> option to the C<new()> method when creating the
|
| 784 |
+
next handle object. After the successful completion of a
|
| 785 |
+
method which requires communication with the server, if the
|
| 786 |
+
new handle object's C<session_id> attribute value matches the
|
| 787 |
+
old session ID then the session has been successfully maintained;
|
| 788 |
+
otherwise, the old session was expired by the cluster.
|
| 789 |
+
|
| 790 |
+
=item get_error()
|
| 791 |
+
|
| 792 |
+
$code = $zkh->get_error();
|
| 793 |
+
|
| 794 |
+
Returns the ZooKeeper error code, if any, from the most
|
| 795 |
+
recent Net::ZooKeeper method invocation. The returned value
|
| 796 |
+
will be zero (equivalent to C<ZOK>) if no error occurred,
|
| 797 |
+
otherwise non-zero. Non-zero values may be compared to
|
| 798 |
+
the error code names exported by the C<:errors> tagset.
|
| 799 |
+
|
| 800 |
+
See L</Error Handling> for more details.
|
| 801 |
+
|
| 802 |
+
=item add_auth()
|
| 803 |
+
|
| 804 |
+
$zkh->add_auth('digest', "$username:$password");
|
| 805 |
+
|
| 806 |
+
The C<add_auth()> method may be used to add authentication
|
| 807 |
+
credentials to a session. Once a credential has been added for
|
| 808 |
+
the current session, there is no way to disable it.
|
| 809 |
+
|
| 810 |
+
When using the digest authentication scheme, note that the
|
| 811 |
+
username and password are transmitted in cleartext
|
| 812 |
+
to the ZooKeeper cluster.
|
| 813 |
+
|
| 814 |
+
See L</Access Control> for additional details.
|
| 815 |
+
|
| 816 |
+
=item create()
|
| 817 |
+
|
| 818 |
+
$path = $zkh->create($req_path, $data);
|
| 819 |
+
$path = $zkh->create($req_path, $data,
|
| 820 |
+
'flags' => (ZOO_EPHEMERAL | ZOO_SEQUENCE),
|
| 821 |
+
'acl' => ZOO_OPEN_ACL_UNSAFE,
|
| 822 |
+
'path_read_len' => 100);
|
| 823 |
+
|
| 824 |
+
Requests that a node be created in the ZooKeeper cluster's
|
| 825 |
+
hierarchy with the given path and data. Upon success,
|
| 826 |
+
the returns the node's path, otherwise undef.
|
| 827 |
+
|
| 828 |
+
The path returned by a successful C<create()> method call
|
| 829 |
+
may not be the new node's full path as it appears in the
|
| 830 |
+
ZooKeeper hierarchy, depending on the length of the actual
|
| 831 |
+
path and the value of the handle object's C<path_read_len>
|
| 832 |
+
attribute. If the length of the actual path exceeds the
|
| 833 |
+
current value of the C<path_read_len> attribute, the path
|
| 834 |
+
returned by the C<create()> method will be truncated; note
|
| 835 |
+
that the node's path in the ZooKeeper hierarchy is not
|
| 836 |
+
affected by this truncation.
|
| 837 |
+
|
| 838 |
+
Specifying a value for the C<'path_read_len'> option will
|
| 839 |
+
temporarily override the value of the C<path_read_len>
|
| 840 |
+
attribute for the duration of the C<create()> method.
|
| 841 |
+
|
| 842 |
+
The flag values available for use with the C<'flags'> option
|
| 843 |
+
are C<ZOO_EPHEMERAL> and C<ZOO_SEQUENCE>; both are
|
| 844 |
+
included in the C<:flags> tagset. The flags should be
|
| 845 |
+
combined with the bitwise OR operator if more than one
|
| 846 |
+
is required.
|
| 847 |
+
|
| 848 |
+
The C<ZOO_EPHEMERAL> flag causes the node to be marked as
|
| 849 |
+
ephemeral, meaning it will be automatically deleted if it
|
| 850 |
+
still exists when the client's session ends. The
|
| 851 |
+
C<ZOO_SEQUENCE> flag causes a unique integer to be appended
|
| 852 |
+
to the node's final path component. See the ZooKeeper
|
| 853 |
+
documentation for additional advice on how to use these flags.
|
| 854 |
+
|
| 855 |
+
When creating a node it may be important to define an ACL
|
| 856 |
+
for it; to do this, pass a reference to an ACL array (as
|
| 857 |
+
described in L</Access Control>) using the C<'acl'> option.
|
| 858 |
+
See also the C<:acl_perms> and C<:acls> tagsets for lists
|
| 859 |
+
of the available ACL permission flags and pre-defined ACLs.
|
| 860 |
+
|
| 861 |
+
=item delete()
|
| 862 |
+
|
| 863 |
+
$ret = $zkh->delete($path);
|
| 864 |
+
$ret = $zkh->delete($path, 'version' => $version);
|
| 865 |
+
|
| 866 |
+
Requests that a node be deleted from the ZooKeeper hierarchy.
|
| 867 |
+
Returns true upon success, false otherwise.
|
| 868 |
+
|
| 869 |
+
If a value for the C<'version'> option is supplied, the node
|
| 870 |
+
will only be deleted if its version number matches the given
|
| 871 |
+
value. See the C<version> attribute of the Net::ZooKeeper::Stat
|
| 872 |
+
class for details on node version numbering.
|
| 873 |
+
|
| 874 |
+
=item exists()
|
| 875 |
+
|
| 876 |
+
$ret = $zkh->exists($path);
|
| 877 |
+
$ret = $zkh->exists($path, 'stat' => $stat, 'watch' => $watch);
|
| 878 |
+
|
| 879 |
+
Tests whether a given node exists. Returns true if the node
|
| 880 |
+
exists, otherwise false. When the C<exists()> method is successful
|
| 881 |
+
but the node does not exist, it returns false, and C<get_error()>
|
| 882 |
+
will return C<ZNONODE> until another method is called on the
|
| 883 |
+
handle object.
|
| 884 |
+
|
| 885 |
+
The C<'stat'> option may be used to request that a
|
| 886 |
+
Net::ZooKeeper::Stat object be updated with the node's
|
| 887 |
+
current state information. The stat object will only be
|
| 888 |
+
updated if the node exists and the C<exists()> method
|
| 889 |
+
succeeds. The stat object must first have been created
|
| 890 |
+
using the C<stat()> method.
|
| 891 |
+
|
| 892 |
+
The C<'watch'> option may be used to request that a
|
| 893 |
+
Net::ZooKeeper::Watch object be assigned to receive
|
| 894 |
+
notification of an event which alters the node's data.
|
| 895 |
+
The watch object must first have been created using the
|
| 896 |
+
C<watch()> method. If the watch object was previously
|
| 897 |
+
assigned to receive notifications for another node, it
|
| 898 |
+
will be reassigned even if the C<exists()> method fails.
|
| 899 |
+
|
| 900 |
+
=item get_children()
|
| 901 |
+
|
| 902 |
+
@child_names = $zkh->get_children($path);
|
| 903 |
+
$num_children = $zkh->get_children($path, 'watch' => $watch);
|
| 904 |
+
|
| 905 |
+
Queries the names or number of the child nodes stored beneath
|
| 906 |
+
a given node in the ZooKeeper hierarchy. In a list context,
|
| 907 |
+
returns a list of the child nodes' names upon success, otherwise
|
| 908 |
+
an empty list. When the C<get_children()> method is successful
|
| 909 |
+
but there are no child nodes, it returns an empty list, and
|
| 910 |
+
C<get_error()> will return C<ZOK> until another method is called
|
| 911 |
+
on the handle object.
|
| 912 |
+
|
| 913 |
+
In a scalar context, C<get_children()> returns the number
|
| 914 |
+
of child nodes upon success, otherwise undef.
|
| 915 |
+
|
| 916 |
+
The names of the child nodes are simply the final component
|
| 917 |
+
of the nodes' paths, i.e., the portion of their path which
|
| 918 |
+
follows the path of the given parent node, excluding the
|
| 919 |
+
"/" delimiter.
|
| 920 |
+
|
| 921 |
+
The C<'watch'> option may be used to request that a
|
| 922 |
+
Net::ZooKeeper::Watch object be assigned to receive
|
| 923 |
+
notification of an event which alters the node's list of
|
| 924 |
+
child nodes. The watch object must first have been created
|
| 925 |
+
using the C<watch()> method. If the watch object was
|
| 926 |
+
previously assigned to receive notifications for another node,
|
| 927 |
+
it will be reassigned even if the C<get_children()> method fails.
|
| 928 |
+
|
| 929 |
+
=item get()
|
| 930 |
+
|
| 931 |
+
$data = $zkh->get($path);
|
| 932 |
+
$data = $zkh->get($path, 'data_read_len' => 100,
|
| 933 |
+
'stat' => $stat, 'watch' => $watch);
|
| 934 |
+
|
| 935 |
+
Queries the data stored in a given node. Returns the
|
| 936 |
+
data as a string upon success, otherwise undef. Note
|
| 937 |
+
that the data may contain nulls if the node's data is
|
| 938 |
+
not a text string.
|
| 939 |
+
|
| 940 |
+
If the length of the node's data exceeds the current value
|
| 941 |
+
of the handle object's C<data_read_len> attribute, the
|
| 942 |
+
string returned by the C<get()> method will be truncated;
|
| 943 |
+
note that the node's data in the ZooKeeper cluster is not
|
| 944 |
+
affected by this truncation.
|
| 945 |
+
|
| 946 |
+
Specifying a value for the C<'data_read_len'> option will
|
| 947 |
+
temporarily override the value of the C<data_read_len>
|
| 948 |
+
attribute for the duration of the C<get()> method.
|
| 949 |
+
|
| 950 |
+
The C<'stat'> option may be used to request that a
|
| 951 |
+
Net::ZooKeeper::Stat object be updated with the node's
|
| 952 |
+
current state information. The stat object will only be
|
| 953 |
+
updated if the C<get()> method succeeds. The stat object
|
| 954 |
+
must first have been created using the C<stat()> method.
|
| 955 |
+
|
| 956 |
+
The C<'watch'> option may be used to request that a
|
| 957 |
+
Net::ZooKeeper::Watch object be assigned to receive
|
| 958 |
+
notification of an event which alters the node's data.
|
| 959 |
+
The watch object must first have been created using the
|
| 960 |
+
C<watch()> method. If the watch object was previously
|
| 961 |
+
assigned to receive notifications for another node, it
|
| 962 |
+
will be reassigned even if the C<get()> method fails.
|
| 963 |
+
|
| 964 |
+
=item set()
|
| 965 |
+
|
| 966 |
+
$ret = $zkh->set($path, $data);
|
| 967 |
+
$ret = $zkh->set($path, $data, 'version' => $version,
|
| 968 |
+
'stat' => $stat);
|
| 969 |
+
|
| 970 |
+
Requests that a node's data be updated in the ZooKeeper
|
| 971 |
+
hierarchy. Returns true upon success, false otherwise.
|
| 972 |
+
|
| 973 |
+
If a value for the C<'version'> option is supplied, the node's
|
| 974 |
+
data will only be updated if its version number matches the
|
| 975 |
+
given value. See the C<version> attribute of the
|
| 976 |
+
Net::ZooKeeper::Stat class for details on node version numbering.
|
| 977 |
+
|
| 978 |
+
The C<'stat'> option may be used to request that a
|
| 979 |
+
Net::ZooKeeper::Stat object be updated with the node's
|
| 980 |
+
current state information. The stat object will only be
|
| 981 |
+
updated if the C<set()> method succeeds. The stat object
|
| 982 |
+
must first have been created using the C<stat()> method.
|
| 983 |
+
|
| 984 |
+
=item get_acl()
|
| 985 |
+
|
| 986 |
+
@acl = $zkh->get_acl($path);
|
| 987 |
+
$num_acl_entries = $zkh->get_acl($path, 'stat' => $stat);
|
| 988 |
+
|
| 989 |
+
Queries the ACL associated with a node in the ZooKeeper
|
| 990 |
+
hierarchy, if any. In a list context, returns an array with
|
| 991 |
+
the node's ACL entries upon success, otherwise
|
| 992 |
+
an empty list. When the C<get_acl()> method is successful
|
| 993 |
+
but there are no ACL entries, it returns an empty list, and
|
| 994 |
+
C<get_error()> will return C<ZOK> until another method is called
|
| 995 |
+
on the handle object.
|
| 996 |
+
|
| 997 |
+
The elements of the returned array are hashes, each of which
|
| 998 |
+
represents one ACL entry. Each hash contains C<perms>,
|
| 999 |
+
C<scheme>, and C<id> elements. See the L</Access Control>
|
| 1000 |
+
section for additional details, and the
|
| 1001 |
+
C<:acl_perms> and C<:acls> tagsets for lists of the
|
| 1002 |
+
available ACL permission flags and pre-defined ACLs.
|
| 1003 |
+
|
| 1004 |
+
In a scalar context, C<get_acl()> returns the number
|
| 1005 |
+
of ACL entries upon success, otherwise undef.
|
| 1006 |
+
|
| 1007 |
+
The C<'stat'> option may be used to request that a
|
| 1008 |
+
Net::ZooKeeper::Stat object be updated with the node's
|
| 1009 |
+
current state information. The stat object will only be
|
| 1010 |
+
updated if the C<get_acl()> method succeeds. The stat object
|
| 1011 |
+
must first have been created using the C<stat()> method.
|
| 1012 |
+
|
| 1013 |
+
=item set_acl()
|
| 1014 |
+
|
| 1015 |
+
$acl = [{
|
| 1016 |
+
'perms' => (ZOO_PERM_READ | ZOO_PERM_WRITE),
|
| 1017 |
+
'scheme' => 'digest',
|
| 1018 |
+
'id' => "$username:$digest"
|
| 1019 |
+
}];
|
| 1020 |
+
$ret = $zkh->set_acl($path, $acl);
|
| 1021 |
+
$ret = $zkh->set_acl($path, ZOO_OPEN_ACL_UNSAFE,
|
| 1022 |
+
'version' => $version);
|
| 1023 |
+
|
| 1024 |
+
Requests that a node's ACL be updated in the ZooKeeper
|
| 1025 |
+
hierarchy. Returns true upon success, false otherwise.
|
| 1026 |
+
|
| 1027 |
+
The ACL should be passed as a reference to an array of
|
| 1028 |
+
hashes, where each hash represents one ACL entry. Each
|
| 1029 |
+
hash should contain C<perms>, C<scheme>, and C<id> elements
|
| 1030 |
+
as described in the L</Access Control> section.
|
| 1031 |
+
See also the C<:acl_perms> and C<:acls> tagsets for lists
|
| 1032 |
+
of the available ACL permission flags and pre-defined ACLs.
|
| 1033 |
+
|
| 1034 |
+
If a value for the C<'version'> option is supplied, the node's
|
| 1035 |
+
ACL will only be updated if its version number matches the
|
| 1036 |
+
given value. See the C<version> attribute of the
|
| 1037 |
+
Net::ZooKeeper::Stat class for details on node version numbering.
|
| 1038 |
+
|
| 1039 |
+
=item stat()
|
| 1040 |
+
|
| 1041 |
+
$stat = $zkh->stat();
|
| 1042 |
+
|
| 1043 |
+
Creates a new Net::ZooKeeper::Stat object which may be used
|
| 1044 |
+
with the C<'stat'> option of the C<exists()>, C<get()>,
|
| 1045 |
+
C<set()>, and C<get_acl()> methods. When the stat object
|
| 1046 |
+
is passed to any of these methods, upon success its attribute
|
| 1047 |
+
values are updated to reflect the current state of the
|
| 1048 |
+
node specified in the method call. The stat object is not
|
| 1049 |
+
updated if the method call does not succeed.
|
| 1050 |
+
|
| 1051 |
+
=item watch()
|
| 1052 |
+
|
| 1053 |
+
$watch = $zkh->watch();
|
| 1054 |
+
$watch = $zkh->watch('timeout' => $timeout);
|
| 1055 |
+
|
| 1056 |
+
Creates a new Net::ZooKeeper::Watch object which may be
|
| 1057 |
+
used to wait for event notifications from the ZooKeeper
|
| 1058 |
+
cluster. Each time the watch object is passed to any
|
| 1059 |
+
of the C<exists()>, C<get_children()>, or C<get()> methods,
|
| 1060 |
+
its attribute values are immediately reset to zero, and will
|
| 1061 |
+
later be updated upon receipt of an appropriate event
|
| 1062 |
+
notification for the node specified in the method call.
|
| 1063 |
+
|
| 1064 |
+
The specific types of events which cause notifications to be
|
| 1065 |
+
sent by the ZooKeeper cluster depend on the method call used.
|
| 1066 |
+
After use with the C<exists()> and C<get()> methods, the
|
| 1067 |
+
watch object will be set to receive an event notification
|
| 1068 |
+
caused by a modification of the node's data or the node itself
|
| 1069 |
+
(e.g., deletion of the node). After use with the
|
| 1070 |
+
C<get_children()> method, the watch object will be set to
|
| 1071 |
+
receive an event notification caused by a modification
|
| 1072 |
+
of the node's list of child nodes.
|
| 1073 |
+
|
| 1074 |
+
Watch objects receive at most one event notification after
|
| 1075 |
+
their assignment to a node by one of the C<exists()>,
|
| 1076 |
+
C<get_children()>, or C<get()> methods. Note that in the
|
| 1077 |
+
case of an error, the watch object may never receive any
|
| 1078 |
+
event notification. However, when the parent Net::ZooKeeper
|
| 1079 |
+
handle object experiences a connection error, the ZooKeeper
|
| 1080 |
+
client code will notify all pending watches with an event of
|
| 1081 |
+
type C<ZOO_SESSION_EVENT>. See C<wait()> for more information
|
| 1082 |
+
regarding the watch object's attribute values after a
|
| 1083 |
+
connection error.
|
| 1084 |
+
|
| 1085 |
+
A watch object may be reused with another C<exists()>,
|
| 1086 |
+
C<get_children()>, or C<get()> method call at any time,
|
| 1087 |
+
in which case the watch object's attribute values
|
| 1088 |
+
are reset to zero and the watch object will no longer be updated
|
| 1089 |
+
by any event notification relevant to the previous method call.
|
| 1090 |
+
|
| 1091 |
+
When the C<watch()> method is invoked without a C<'timeout'>
|
| 1092 |
+
option, it returns a newly created watch object whose C<timeout>
|
| 1093 |
+
attribute value is initialized to the current value of the
|
| 1094 |
+
Net::ZooKeeper handle object's C<watch_timeout> attribute.
|
| 1095 |
+
Otherwise, when the C<watch()> method is invoked with a
|
| 1096 |
+
C<'timeout'> option, the new watch object's C<timeout> attribute
|
| 1097 |
+
value is initialized to the value specified by the
|
| 1098 |
+
C<'timeout'> option.
|
| 1099 |
+
|
| 1100 |
+
See also the C<watch_timeout> attribute, and the C<timeout>
|
| 1101 |
+
attribute and C<wait()> method of the Net::ZooKeeper::Watch
|
| 1102 |
+
class.
|
| 1103 |
+
|
| 1104 |
+
=back
|
| 1105 |
+
|
| 1106 |
+
=head2 Net::ZooKeeper::Stat
|
| 1107 |
+
|
| 1108 |
+
No methods are defined for the Net::ZooKeeper::Stat class.
|
| 1109 |
+
|
| 1110 |
+
=head2 Net::ZooKeeper::Watch
|
| 1111 |
+
|
| 1112 |
+
Only one method is defined for the Net::ZooKeeper::Watch class.
|
| 1113 |
+
|
| 1114 |
+
=over 4
|
| 1115 |
+
|
| 1116 |
+
=item wait()
|
| 1117 |
+
|
| 1118 |
+
$ret = $watch->wait();
|
| 1119 |
+
$ret = $watch->wait('timeout' => $timeout);
|
| 1120 |
+
|
| 1121 |
+
Waits for an event notification from the ZooKeeper cluster
|
| 1122 |
+
for the node most recently associated with the watch object.
|
| 1123 |
+
Nodes are associated with a watch object by passing the
|
| 1124 |
+
watch object as the value of a C<'watch'> option to a
|
| 1125 |
+
Net::ZooKeeper method; methods which accept a C<'watch'> option
|
| 1126 |
+
are C<exists()>, C<get_children()>, and C<get()>.
|
| 1127 |
+
|
| 1128 |
+
When the C<wait()> method is invoked with a C<'timeout'>
|
| 1129 |
+
option, it waits for no more than the number of milliseconds
|
| 1130 |
+
specified by the C<'timeout'> option.
|
| 1131 |
+
Otherwise, when the C<wait()> method is invoked without a
|
| 1132 |
+
C<'timeout'> option, it waits for no more than the timeout
|
| 1133 |
+
period specified by the value of the watch object's C<timeout>
|
| 1134 |
+
attribute.
|
| 1135 |
+
|
| 1136 |
+
The C<wait()> method returns true if an event notification
|
| 1137 |
+
was received, otherwise false. When C<wait()> returns true,
|
| 1138 |
+
the C<event> and C<state> attributes of the watch object
|
| 1139 |
+
will be updated with the event's type and the current
|
| 1140 |
+
connection state.
|
| 1141 |
+
|
| 1142 |
+
When the parent Net::ZooKeeper handle object experiences a
|
| 1143 |
+
connection error, the ZooKeeper client code will notify all
|
| 1144 |
+
pending watches with an event of type C<ZOO_SESSION_EVENT>.
|
| 1145 |
+
In this case, the C<state> attribute will report the current
|
| 1146 |
+
state of the connection to the ZooKeeper cluster.
|
| 1147 |
+
|
| 1148 |
+
See also the C<timeout> attribute, and the C<watch()> method
|
| 1149 |
+
and C<watch_timeout> attribute of the Net::ZooKeeper class.
|
| 1150 |
+
|
| 1151 |
+
=back
|
| 1152 |
+
|
| 1153 |
+
=head1 FUNCTIONS
|
| 1154 |
+
|
| 1155 |
+
The following functions have global scope and affect all
|
| 1156 |
+
Net::ZooKeeper handle objects.
|
| 1157 |
+
|
| 1158 |
+
=over 4
|
| 1159 |
+
|
| 1160 |
+
=item set_log_level()
|
| 1161 |
+
|
| 1162 |
+
Net::ZooKeeper::set_log_level($level);
|
| 1163 |
+
|
| 1164 |
+
The C<Net::ZooKeeper::set_log_level()> function may be called to
|
| 1165 |
+
alter the number and type of messages written to the current log
|
| 1166 |
+
file handle (if any). The default value is C<ZOO_LOG_LEVEL_OFF>
|
| 1167 |
+
which disables all logging.
|
| 1168 |
+
|
| 1169 |
+
See the L</Logging> section for more details and C<:log_levels>
|
| 1170 |
+
for a list of the available log levels.
|
| 1171 |
+
|
| 1172 |
+
=item set_deterministic_conn_order()
|
| 1173 |
+
|
| 1174 |
+
Net::ZooKeeper::set_deterministic_conn_order(1);
|
| 1175 |
+
|
| 1176 |
+
The C<Net::ZooKeeper::set_deterministic_conn_order()> function
|
| 1177 |
+
may be called to indicate whether or not the list of ZooKeeper
|
| 1178 |
+
servers passed to the C<new()> method should be randomly permuted.
|
| 1179 |
+
If set to a true value, the list of servers will not be altered.
|
| 1180 |
+
The default false value indicates the list of servers will
|
| 1181 |
+
be randomly reordered prior to connection.
|
| 1182 |
+
|
| 1183 |
+
See the L</Connection Order> section for more details.
|
| 1184 |
+
|
| 1185 |
+
=back
|
| 1186 |
+
|
| 1187 |
+
=head1 EXPORTS
|
| 1188 |
+
|
| 1189 |
+
Nothing is exported by default. Various tagsets exist which
|
| 1190 |
+
group the tags available for export into different categories:
|
| 1191 |
+
|
| 1192 |
+
=over 4
|
| 1193 |
+
|
| 1194 |
+
=item :errors
|
| 1195 |
+
|
| 1196 |
+
ZooKeeper error codes. These may be compared to the values
|
| 1197 |
+
returned by the C<get_error()> method.
|
| 1198 |
+
|
| 1199 |
+
=item :node_flags
|
| 1200 |
+
|
| 1201 |
+
The ZooKeeper node flags C<ZOO_EPHEMERAL> and C<ZOO_SEQUENCE>,
|
| 1202 |
+
which may be passed in the C<'flags'> option to the C<create()>
|
| 1203 |
+
method. When more than node flag is required they
|
| 1204 |
+
should be combined using the bitwise OR operator.
|
| 1205 |
+
|
| 1206 |
+
=item :acl_perms
|
| 1207 |
+
|
| 1208 |
+
The ZooKeeper ACL permission flags which may be used in
|
| 1209 |
+
the value of the C<perms> attribute of an ACL entry hash.
|
| 1210 |
+
When more than one ACL permission flag is required they
|
| 1211 |
+
should be combined using the bitwise OR operator.
|
| 1212 |
+
|
| 1213 |
+
The available ACL permission flags are C<ZOO_PERM_READ>,
|
| 1214 |
+
C<ZOO_PERM_WRITE>, C<ZOO_PERM_CREATE>, C<ZOO_PERM_DELETE>,
|
| 1215 |
+
and C<ZOO_PERM_ADMIN>. For convenience, C<ZOO_PERM_ALL> is
|
| 1216 |
+
defined as the bitwise OR of all of these flags.
|
| 1217 |
+
|
| 1218 |
+
=item :acls
|
| 1219 |
+
|
| 1220 |
+
Common ZooKeeper ACLs which may be useful. C<ZOO_OPEN_ACL_UNSAFE>
|
| 1221 |
+
specifies a node which is entirely open to all users with no
|
| 1222 |
+
restrictions at all. C<ZOO_READ_ACL_UNSAFE> specifies
|
| 1223 |
+
a node which is readable by all users; permissions for other actions
|
| 1224 |
+
are not defined in this ACL. C<ZOO_CREATOR_ALL_ACL> specifies a node
|
| 1225 |
+
for which all actions require the same authentication credentials as
|
| 1226 |
+
held by the session which created the node; this implies that a
|
| 1227 |
+
session should authenticate with an appropriate scheme before
|
| 1228 |
+
creating a node with this ACL.
|
| 1229 |
+
|
| 1230 |
+
=item :events
|
| 1231 |
+
|
| 1232 |
+
The ZooKeeper event types which are returned in value of
|
| 1233 |
+
the C<event> attribute a Net::ZooKeeper::Watch object after
|
| 1234 |
+
an event occurs on a watched node.
|
| 1235 |
+
|
| 1236 |
+
=item :states
|
| 1237 |
+
|
| 1238 |
+
The ZooKeeper connection states which are returned in value of
|
| 1239 |
+
the C<state> attribute of a Net::ZooKeeper::Watch object after
|
| 1240 |
+
an event occurs on a watched node.
|
| 1241 |
+
|
| 1242 |
+
=item :log_levels
|
| 1243 |
+
|
| 1244 |
+
The ZooKeeper log levels which may be passed to the
|
| 1245 |
+
C<Net::ZooKeeper::set_log_level()> function. The available
|
| 1246 |
+
log levels are, from least to most verbose, C<ZOO_LOG_LEVEL_OFF>
|
| 1247 |
+
(the default), C<ZOO_LOG_LEVEL_ERROR>, C<ZOO_LOG_LEVEL_WARN>,
|
| 1248 |
+
C<ZOO_LOG_LEVEL_INFO>, and C<ZOO_LOG_LEVEL_DEBUG>.
|
| 1249 |
+
|
| 1250 |
+
=item :all
|
| 1251 |
+
|
| 1252 |
+
Everything from all of the above tagsets.
|
| 1253 |
+
|
| 1254 |
+
=back
|
| 1255 |
+
|
| 1256 |
+
=head1 SEE ALSO
|
| 1257 |
+
|
| 1258 |
+
The Apache ZooKeeper project's home page at
|
| 1259 |
+
L<http://zookeeper.apache.org/> provides a wealth of detail
|
| 1260 |
+
on how to develop applications using ZooKeeper.
|
| 1261 |
+
|
| 1262 |
+
=head1 AUTHOR
|
| 1263 |
+
|
| 1264 |
+
Chris Darroch, E<lt>chrisd@apache.orgE<gt>
|
| 1265 |
+
|
| 1266 |
+
=head1 COPYRIGHT AND LICENSE
|
| 1267 |
+
|
| 1268 |
+
Licensed to the Apache Software Foundation (ASF) under one
|
| 1269 |
+
or more contributor license agreements. See the NOTICE file
|
| 1270 |
+
distributed with this work for additional information
|
| 1271 |
+
regarding copyright ownership. The ASF licenses this file
|
| 1272 |
+
to you under the Apache License, Version 2.0 (the
|
| 1273 |
+
"License"); you may not use this file except in compliance
|
| 1274 |
+
with the License. You may obtain a copy of the License at
|
| 1275 |
+
|
| 1276 |
+
http://www.apache.org/licenses/LICENSE-2.0
|
| 1277 |
+
|
| 1278 |
+
Unless required by applicable law or agreed to in writing, software
|
| 1279 |
+
distributed under the License is distributed on an "AS IS" BASIS,
|
| 1280 |
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 1281 |
+
See the License for the specific language governing permissions and
|
| 1282 |
+
limitations under the License.
|
| 1283 |
+
|
| 1284 |
+
=cut
|
| 1285 |
+
|
local-test-zookeeper-full-01/afc-zookeeper/zookeeper-contrib/zookeeper-contrib-zkperl/ZooKeeper.xs
ADDED
|
@@ -0,0 +1,2722 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* Net::ZooKeeper - Perl extension for Apache ZooKeeper
|
| 2 |
+
*
|
| 3 |
+
* Licensed to the Apache Software Foundation (ASF) under one
|
| 4 |
+
* or more contributor license agreements. See the NOTICE file
|
| 5 |
+
* distributed with this work for additional information
|
| 6 |
+
* regarding copyright ownership. The ASF licenses this file
|
| 7 |
+
* to you under the Apache License, Version 2.0 (the
|
| 8 |
+
* "License"); you may not use this file except in compliance
|
| 9 |
+
* with the License. You may obtain a copy of the License at
|
| 10 |
+
*
|
| 11 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 12 |
+
*
|
| 13 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 14 |
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
| 15 |
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 16 |
+
* See the License for the specific language governing permissions and
|
| 17 |
+
* limitations under the License.
|
| 18 |
+
*/
|
| 19 |
+
|
| 20 |
+
#define PERL_NO_GET_CONTEXT
|
| 21 |
+
|
| 22 |
+
#include "EXTERN.h"
|
| 23 |
+
#include "perl.h"
|
| 24 |
+
#include "XSUB.h"
|
| 25 |
+
|
| 26 |
+
#include <pthread.h> /* pthread_mutex_lock(), etc. */
|
| 27 |
+
#include <string.h> /* memset(), etc. */
|
| 28 |
+
#include <limits.h> /* CHAR_BIT */
|
| 29 |
+
#include <sys/time.h> /* gettimeofday() */
|
| 30 |
+
|
| 31 |
+
#define THREADED
|
| 32 |
+
#include <zookeeper/zookeeper.h>
|
| 33 |
+
#undef THREADED
|
| 34 |
+
|
| 35 |
+
#include "build/check_zk_version.h"
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
#define PACKAGE_NAME "Net::ZooKeeper"
|
| 39 |
+
#define PACKAGE_SIGNATURE 19631123
|
| 40 |
+
|
| 41 |
+
#define STAT_PACKAGE_NAME "Net::ZooKeeper::Stat"
|
| 42 |
+
#define STAT_PACKAGE_SIGNATURE 19960512
|
| 43 |
+
|
| 44 |
+
#define WATCH_PACKAGE_NAME "Net::ZooKeeper::Watch"
|
| 45 |
+
#define WATCH_PACKAGE_SIGNATURE 20050326
|
| 46 |
+
|
| 47 |
+
#define MAX_KEY_NAME_LEN 16 /* "children_version" */
|
| 48 |
+
|
| 49 |
+
#define NUM_ACL_ENTRY_KEYS 3
|
| 50 |
+
#define NUM_KEYS 7
|
| 51 |
+
#define NUM_STAT_KEYS 11
|
| 52 |
+
#define NUM_WATCH_KEYS 3
|
| 53 |
+
|
| 54 |
+
#define DEFAULT_RECV_TIMEOUT_MSEC 10000
|
| 55 |
+
|
| 56 |
+
#define DEFAULT_DATA_BUF_LEN 1023
|
| 57 |
+
#define DEFAULT_PATH_BUF_LEN 1023
|
| 58 |
+
#define DEFAULT_WATCH_TIMEOUT 60000
|
| 59 |
+
|
| 60 |
+
#define ZOO_LOG_LEVEL_OFF 0
|
| 61 |
+
|
| 62 |
+
#ifndef strcaseEQ
|
| 63 |
+
#define strcaseEQ(a,b) (!strcasecmp((a),(b)))
|
| 64 |
+
#endif
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
typedef struct Stat zk_stat_t;
|
| 68 |
+
|
| 69 |
+
typedef HV* Net__ZooKeeper__Stat;
|
| 70 |
+
|
| 71 |
+
typedef struct zk_watch_t zk_watch_t;
|
| 72 |
+
|
| 73 |
+
struct zk_watch_t {
|
| 74 |
+
pthread_mutex_t mutex;
|
| 75 |
+
pthread_cond_t cond;
|
| 76 |
+
int done;
|
| 77 |
+
int ret;
|
| 78 |
+
int event_type;
|
| 79 |
+
int event_state;
|
| 80 |
+
unsigned int timeout;
|
| 81 |
+
zk_watch_t *prev;
|
| 82 |
+
zk_watch_t *next;
|
| 83 |
+
int ref_count;
|
| 84 |
+
};
|
| 85 |
+
|
| 86 |
+
typedef HV* Net__ZooKeeper__Watch;
|
| 87 |
+
|
| 88 |
+
typedef struct {
|
| 89 |
+
zhandle_t *handle;
|
| 90 |
+
zk_watch_t *first_watch;
|
| 91 |
+
int data_buf_len;
|
| 92 |
+
int path_buf_len;
|
| 93 |
+
unsigned int watch_timeout;
|
| 94 |
+
const char *hosts;
|
| 95 |
+
int hosts_len;
|
| 96 |
+
int last_ret;
|
| 97 |
+
int last_errno;
|
| 98 |
+
} zk_t;
|
| 99 |
+
|
| 100 |
+
typedef HV* Net__ZooKeeper;
|
| 101 |
+
|
| 102 |
+
typedef struct {
|
| 103 |
+
I32 signature;
|
| 104 |
+
union {
|
| 105 |
+
zk_t *zk;
|
| 106 |
+
zk_stat_t *stat;
|
| 107 |
+
zk_watch_t *watch;
|
| 108 |
+
} handle;
|
| 109 |
+
} zk_handle_t;
|
| 110 |
+
|
| 111 |
+
typedef struct {
|
| 112 |
+
const char name[MAX_KEY_NAME_LEN + 1];
|
| 113 |
+
U32 name_len;
|
| 114 |
+
size_t offset;
|
| 115 |
+
size_t size;
|
| 116 |
+
U32 hash;
|
| 117 |
+
} zk_key_t;
|
| 118 |
+
|
| 119 |
+
|
| 120 |
+
static zk_key_t zk_acl_entry_keys[NUM_ACL_ENTRY_KEYS] = {
|
| 121 |
+
{"perms", 0, 0, 0, 0},
|
| 122 |
+
{"scheme", 0, 0, 0, 0},
|
| 123 |
+
{"id", 0, 0, 0, 0}
|
| 124 |
+
};
|
| 125 |
+
|
| 126 |
+
static zk_key_t zk_keys[NUM_KEYS] = {
|
| 127 |
+
{"data_read_len", 0, 0, 0, 0},
|
| 128 |
+
{"path_read_len", 0, 0, 0, 0},
|
| 129 |
+
{"watch_timeout", 0, 0, 0, 0},
|
| 130 |
+
{"hosts", 0, 0, 0, 0},
|
| 131 |
+
{"session_timeout", 0, 0, 0, 0},
|
| 132 |
+
{"session_id", 0, 0, 0, 0},
|
| 133 |
+
{"pending_watches", 0, 0, 0, 0}
|
| 134 |
+
};
|
| 135 |
+
|
| 136 |
+
static zk_key_t zk_stat_keys[NUM_STAT_KEYS] = {
|
| 137 |
+
{"czxid", 0, offsetof(struct Stat, czxid),
|
| 138 |
+
sizeof(((struct Stat*) 0)->czxid), 0},
|
| 139 |
+
{"mzxid", 0, offsetof(struct Stat, mzxid),
|
| 140 |
+
sizeof(((struct Stat*) 0)->mzxid), 0},
|
| 141 |
+
{"ctime", 0, offsetof(struct Stat, ctime),
|
| 142 |
+
sizeof(((struct Stat*) 0)->ctime), 0},
|
| 143 |
+
{"mtime", 0, offsetof(struct Stat, mtime),
|
| 144 |
+
sizeof(((struct Stat*) 0)->mtime), 0},
|
| 145 |
+
{"version", 0, offsetof(struct Stat, version),
|
| 146 |
+
sizeof(((struct Stat*) 0)->version), 0},
|
| 147 |
+
{"children_version", 0, offsetof(struct Stat, cversion),
|
| 148 |
+
sizeof(((struct Stat*) 0)->cversion), 0},
|
| 149 |
+
{"acl_version", 0, offsetof(struct Stat, aversion),
|
| 150 |
+
sizeof(((struct Stat*) 0)->aversion), 0},
|
| 151 |
+
{"ephemeral_owner", 0, offsetof(struct Stat, ephemeralOwner),
|
| 152 |
+
sizeof(((struct Stat*) 0)->ephemeralOwner), 0},
|
| 153 |
+
{"data_len", 0, offsetof(struct Stat, dataLength),
|
| 154 |
+
sizeof(((struct Stat*) 0)->dataLength), 0},
|
| 155 |
+
{"num_children", 0, offsetof(struct Stat, numChildren),
|
| 156 |
+
sizeof(((struct Stat*) 0)->numChildren), 0},
|
| 157 |
+
{"children_zxid", 0, offsetof(struct Stat, pzxid),
|
| 158 |
+
sizeof(((struct Stat*) 0)->pzxid), 0}
|
| 159 |
+
};
|
| 160 |
+
|
| 161 |
+
static zk_key_t zk_watch_keys[NUM_WATCH_KEYS] = {
|
| 162 |
+
{"timeout", 0, 0, 0, 0},
|
| 163 |
+
{"event", 0, 0, 0, 0},
|
| 164 |
+
{"state", 0, 0, 0, 0}
|
| 165 |
+
};
|
| 166 |
+
|
| 167 |
+
|
| 168 |
+
static void _zk_watcher(zhandle_t *handle, int type, int state,
|
| 169 |
+
const char *path, void *context)
|
| 170 |
+
{
|
| 171 |
+
zk_watch_t *watch_ctx = context;
|
| 172 |
+
|
| 173 |
+
pthread_mutex_lock(&watch_ctx->mutex);
|
| 174 |
+
|
| 175 |
+
watch_ctx->event_type = type;
|
| 176 |
+
watch_ctx->event_state = state;
|
| 177 |
+
|
| 178 |
+
watch_ctx->done = 1;
|
| 179 |
+
|
| 180 |
+
pthread_cond_signal(&watch_ctx->cond);
|
| 181 |
+
pthread_mutex_unlock(&watch_ctx->mutex);
|
| 182 |
+
|
| 183 |
+
return;
|
| 184 |
+
}
|
| 185 |
+
|
| 186 |
+
static void _zk_auth_completion(int ret, const void *data)
|
| 187 |
+
{
|
| 188 |
+
zk_watch_t *watch_ctx = (zk_watch_t*) data;
|
| 189 |
+
|
| 190 |
+
pthread_mutex_lock(&watch_ctx->mutex);
|
| 191 |
+
|
| 192 |
+
watch_ctx->ret = ret;
|
| 193 |
+
|
| 194 |
+
watch_ctx->done = 1;
|
| 195 |
+
|
| 196 |
+
pthread_cond_signal(&watch_ctx->cond);
|
| 197 |
+
pthread_mutex_unlock(&watch_ctx->mutex);
|
| 198 |
+
|
| 199 |
+
return;
|
| 200 |
+
}
|
| 201 |
+
|
| 202 |
+
static zk_watch_t *_zk_create_watch(pTHX)
|
| 203 |
+
{
|
| 204 |
+
zk_watch_t *watch;
|
| 205 |
+
|
| 206 |
+
Newxz(watch, 1, zk_watch_t);
|
| 207 |
+
|
| 208 |
+
if (pthread_mutex_init(&watch->mutex, NULL)) {
|
| 209 |
+
int save_errno = errno;
|
| 210 |
+
|
| 211 |
+
Safefree(watch);
|
| 212 |
+
|
| 213 |
+
errno = save_errno;
|
| 214 |
+
return NULL;
|
| 215 |
+
}
|
| 216 |
+
|
| 217 |
+
if (pthread_cond_init(&watch->cond, NULL)) {
|
| 218 |
+
int save_errno = errno;
|
| 219 |
+
|
| 220 |
+
pthread_mutex_destroy(&watch->mutex);
|
| 221 |
+
Safefree(watch);
|
| 222 |
+
|
| 223 |
+
errno = save_errno;
|
| 224 |
+
return NULL;
|
| 225 |
+
}
|
| 226 |
+
|
| 227 |
+
return watch;
|
| 228 |
+
}
|
| 229 |
+
|
| 230 |
+
static void _zk_destroy_watch(pTHX_ zk_watch_t *watch)
|
| 231 |
+
{
|
| 232 |
+
pthread_cond_destroy(&watch->cond);
|
| 233 |
+
pthread_mutex_destroy(&watch->mutex);
|
| 234 |
+
|
| 235 |
+
Safefree(watch);
|
| 236 |
+
|
| 237 |
+
return;
|
| 238 |
+
}
|
| 239 |
+
|
| 240 |
+
static zk_watch_t *_zk_acquire_watch(pTHX)
|
| 241 |
+
{
|
| 242 |
+
zk_watch_t *watch = _zk_create_watch(aTHX);
|
| 243 |
+
|
| 244 |
+
if (watch) {
|
| 245 |
+
watch->ref_count = 1;
|
| 246 |
+
}
|
| 247 |
+
|
| 248 |
+
return watch;
|
| 249 |
+
}
|
| 250 |
+
|
| 251 |
+
static void _zk_release_watch(pTHX_ zk_watch_t *watch, int list)
|
| 252 |
+
{
|
| 253 |
+
if (list) {
|
| 254 |
+
if (watch->prev) {
|
| 255 |
+
watch->prev->next = watch->next;
|
| 256 |
+
}
|
| 257 |
+
if (watch->next) {
|
| 258 |
+
watch->next->prev = watch->prev;
|
| 259 |
+
}
|
| 260 |
+
watch->prev = NULL;
|
| 261 |
+
watch->next = NULL;
|
| 262 |
+
}
|
| 263 |
+
|
| 264 |
+
if (--watch->ref_count == 0) {
|
| 265 |
+
_zk_destroy_watch(aTHX_ watch);
|
| 266 |
+
}
|
| 267 |
+
|
| 268 |
+
return;
|
| 269 |
+
}
|
| 270 |
+
|
| 271 |
+
static unsigned int _zk_release_watches(pTHX_ zk_watch_t *first_watch,
|
| 272 |
+
int final)
|
| 273 |
+
{
|
| 274 |
+
zk_watch_t *watch = first_watch->next;
|
| 275 |
+
unsigned int pending_watches = 0;
|
| 276 |
+
|
| 277 |
+
while (watch) {
|
| 278 |
+
zk_watch_t *next_watch = watch->next;
|
| 279 |
+
int done = final;
|
| 280 |
+
|
| 281 |
+
if (!final) {
|
| 282 |
+
pthread_mutex_lock(&watch->mutex);
|
| 283 |
+
done = watch->done;
|
| 284 |
+
pthread_mutex_unlock(&watch->mutex);
|
| 285 |
+
}
|
| 286 |
+
|
| 287 |
+
if (done) {
|
| 288 |
+
_zk_release_watch(aTHX_ watch, 1);
|
| 289 |
+
}
|
| 290 |
+
else {
|
| 291 |
+
++pending_watches;
|
| 292 |
+
}
|
| 293 |
+
|
| 294 |
+
watch = next_watch;
|
| 295 |
+
}
|
| 296 |
+
|
| 297 |
+
return pending_watches;
|
| 298 |
+
}
|
| 299 |
+
|
| 300 |
+
static void _zk_replace_watch(pTHX_ zk_handle_t *handle,
|
| 301 |
+
zk_watch_t *first_watch,
|
| 302 |
+
zk_watch_t *old_watch, zk_watch_t *new_watch)
|
| 303 |
+
{
|
| 304 |
+
zk_watch_t *next_watch;
|
| 305 |
+
|
| 306 |
+
new_watch->timeout = old_watch->timeout;
|
| 307 |
+
|
| 308 |
+
_zk_release_watch(aTHX_ old_watch, 0);
|
| 309 |
+
|
| 310 |
+
/* cleanup any completed watches not tied to a handle */
|
| 311 |
+
_zk_release_watches(aTHX_ first_watch, 0);
|
| 312 |
+
|
| 313 |
+
next_watch = first_watch->next;
|
| 314 |
+
|
| 315 |
+
new_watch->prev = first_watch;
|
| 316 |
+
new_watch->next = next_watch;
|
| 317 |
+
|
| 318 |
+
if (next_watch) {
|
| 319 |
+
next_watch->prev = new_watch;
|
| 320 |
+
}
|
| 321 |
+
|
| 322 |
+
first_watch->next = new_watch;
|
| 323 |
+
|
| 324 |
+
++new_watch->ref_count;
|
| 325 |
+
|
| 326 |
+
handle->handle.watch = new_watch;
|
| 327 |
+
|
| 328 |
+
return;
|
| 329 |
+
}
|
| 330 |
+
|
| 331 |
+
static void _zk_free_acl(pTHX_ struct ACL_vector *acl)
|
| 332 |
+
{
|
| 333 |
+
if (acl->data) {
|
| 334 |
+
Safefree(acl->data);
|
| 335 |
+
}
|
| 336 |
+
|
| 337 |
+
return;
|
| 338 |
+
}
|
| 339 |
+
|
| 340 |
+
static const char *_zk_fill_acl(pTHX_ AV *acl_arr, struct ACL_vector *acl)
|
| 341 |
+
{
|
| 342 |
+
I32 num_acl_entries = av_len(acl_arr) + 1;
|
| 343 |
+
int i;
|
| 344 |
+
|
| 345 |
+
Zero(acl, 1, struct ACL_vector);
|
| 346 |
+
|
| 347 |
+
if (num_acl_entries <= 0) {
|
| 348 |
+
return NULL;
|
| 349 |
+
}
|
| 350 |
+
else if (num_acl_entries > PERL_INT_MAX) {
|
| 351 |
+
num_acl_entries = PERL_INT_MAX;
|
| 352 |
+
}
|
| 353 |
+
|
| 354 |
+
Newx(acl->data, num_acl_entries, struct ACL);
|
| 355 |
+
|
| 356 |
+
for (i = 0; i < num_acl_entries; ++i) {
|
| 357 |
+
SV **acl_entry_ptr;
|
| 358 |
+
HV *acl_entry_hash;
|
| 359 |
+
zk_key_t *key;
|
| 360 |
+
SV **val_ptr;
|
| 361 |
+
struct ACL acl_entry;
|
| 362 |
+
|
| 363 |
+
acl_entry_ptr = av_fetch(acl_arr, i, 0);
|
| 364 |
+
|
| 365 |
+
if (!acl_entry_ptr) {
|
| 366 |
+
continue;
|
| 367 |
+
}
|
| 368 |
+
|
| 369 |
+
if (!SvROK(*acl_entry_ptr) ||
|
| 370 |
+
SvTYPE(SvRV(*acl_entry_ptr)) != SVt_PVHV) {
|
| 371 |
+
_zk_free_acl(aTHX_ acl);
|
| 372 |
+
|
| 373 |
+
return "invalid ACL entry hash reference";
|
| 374 |
+
}
|
| 375 |
+
|
| 376 |
+
acl_entry_hash = (HV*) SvRV(*acl_entry_ptr);
|
| 377 |
+
|
| 378 |
+
key = &zk_acl_entry_keys[0];
|
| 379 |
+
val_ptr = hv_fetch(acl_entry_hash, key->name, key->name_len, 0);
|
| 380 |
+
|
| 381 |
+
if (!val_ptr) {
|
| 382 |
+
_zk_free_acl(aTHX_ acl);
|
| 383 |
+
|
| 384 |
+
return "no ACL entry perms element";
|
| 385 |
+
}
|
| 386 |
+
|
| 387 |
+
acl_entry.perms = SvIV(*val_ptr);
|
| 388 |
+
|
| 389 |
+
if (!acl_entry.perms || (acl_entry.perms & ~ZOO_PERM_ALL)) {
|
| 390 |
+
_zk_free_acl(aTHX_ acl);
|
| 391 |
+
|
| 392 |
+
return "invalid ACL entry perms";
|
| 393 |
+
}
|
| 394 |
+
|
| 395 |
+
key = &zk_acl_entry_keys[1];
|
| 396 |
+
val_ptr = hv_fetch(acl_entry_hash, key->name, key->name_len, 0);
|
| 397 |
+
|
| 398 |
+
if (!val_ptr) {
|
| 399 |
+
_zk_free_acl(aTHX_ acl);
|
| 400 |
+
|
| 401 |
+
return "no ACL entry scheme element";
|
| 402 |
+
}
|
| 403 |
+
|
| 404 |
+
acl_entry.id.scheme = SvPV_nolen(*val_ptr);
|
| 405 |
+
|
| 406 |
+
key = &zk_acl_entry_keys[2];
|
| 407 |
+
val_ptr = hv_fetch(acl_entry_hash, key->name, key->name_len, 0);
|
| 408 |
+
|
| 409 |
+
if (!val_ptr) {
|
| 410 |
+
_zk_free_acl(aTHX_ acl);
|
| 411 |
+
|
| 412 |
+
return "no ACL entry id element";
|
| 413 |
+
}
|
| 414 |
+
|
| 415 |
+
acl_entry.id.id = SvPV_nolen(*val_ptr);
|
| 416 |
+
|
| 417 |
+
++acl->count;
|
| 418 |
+
acl->data[i] = acl_entry;
|
| 419 |
+
}
|
| 420 |
+
|
| 421 |
+
return NULL;
|
| 422 |
+
}
|
| 423 |
+
|
| 424 |
+
static void _zk_fill_acl_entry_hash(pTHX_ struct ACL *acl_entry,
|
| 425 |
+
HV *acl_entry_hash)
|
| 426 |
+
{
|
| 427 |
+
zk_key_t *key;
|
| 428 |
+
SV *val;
|
| 429 |
+
|
| 430 |
+
key = &zk_acl_entry_keys[0];
|
| 431 |
+
val = newSViv(acl_entry->perms);
|
| 432 |
+
|
| 433 |
+
if (!hv_store(acl_entry_hash, key->name, key->name_len, val, key->hash)) {
|
| 434 |
+
SvREFCNT_dec(val);
|
| 435 |
+
}
|
| 436 |
+
|
| 437 |
+
key = &zk_acl_entry_keys[1];
|
| 438 |
+
val = newSVpv(acl_entry->id.scheme, 0);
|
| 439 |
+
|
| 440 |
+
if (!hv_store(acl_entry_hash, key->name, key->name_len, val, key->hash)) {
|
| 441 |
+
SvREFCNT_dec(val);
|
| 442 |
+
}
|
| 443 |
+
|
| 444 |
+
key = &zk_acl_entry_keys[2];
|
| 445 |
+
val = newSVpv(acl_entry->id.id, 0);
|
| 446 |
+
|
| 447 |
+
if (!hv_store(acl_entry_hash, key->name, key->name_len, val, key->hash)) {
|
| 448 |
+
SvREFCNT_dec(val);
|
| 449 |
+
}
|
| 450 |
+
|
| 451 |
+
return;
|
| 452 |
+
}
|
| 453 |
+
|
| 454 |
+
static zk_handle_t *_zk_check_handle_inner(pTHX_ HV *attr_hash,
|
| 455 |
+
I32 package_signature)
|
| 456 |
+
{
|
| 457 |
+
zk_handle_t *handle = NULL;
|
| 458 |
+
|
| 459 |
+
if (SvRMAGICAL(attr_hash)) {
|
| 460 |
+
MAGIC *magic = mg_find((SV*) attr_hash, PERL_MAGIC_ext);
|
| 461 |
+
|
| 462 |
+
if (magic) {
|
| 463 |
+
handle = (zk_handle_t*) magic->mg_ptr;
|
| 464 |
+
|
| 465 |
+
if (handle->signature != package_signature) {
|
| 466 |
+
handle = NULL;
|
| 467 |
+
}
|
| 468 |
+
}
|
| 469 |
+
}
|
| 470 |
+
|
| 471 |
+
return handle;
|
| 472 |
+
}
|
| 473 |
+
|
| 474 |
+
static zk_handle_t *_zk_check_handle_outer(pTHX_ HV *hash, HV **attr_hash_ptr,
|
| 475 |
+
const char *package_name,
|
| 476 |
+
I32 package_signature)
|
| 477 |
+
{
|
| 478 |
+
zk_handle_t *handle = NULL;
|
| 479 |
+
|
| 480 |
+
if (attr_hash_ptr) {
|
| 481 |
+
*attr_hash_ptr = NULL;
|
| 482 |
+
}
|
| 483 |
+
|
| 484 |
+
if (SvRMAGICAL((SV*) hash)) {
|
| 485 |
+
MAGIC *magic = mg_find((SV*) hash, PERL_MAGIC_tied);
|
| 486 |
+
|
| 487 |
+
if (magic) {
|
| 488 |
+
SV *attr = magic->mg_obj;
|
| 489 |
+
|
| 490 |
+
if (SvROK(attr) && SvTYPE(SvRV(attr)) == SVt_PVHV &&
|
| 491 |
+
sv_derived_from(attr, package_name)) {
|
| 492 |
+
HV *attr_hash = (HV*) SvRV(attr);
|
| 493 |
+
|
| 494 |
+
handle = _zk_check_handle_inner(aTHX_ attr_hash,
|
| 495 |
+
package_signature);
|
| 496 |
+
|
| 497 |
+
if (handle && attr_hash_ptr) {
|
| 498 |
+
*attr_hash_ptr = attr_hash;
|
| 499 |
+
}
|
| 500 |
+
}
|
| 501 |
+
}
|
| 502 |
+
}
|
| 503 |
+
|
| 504 |
+
return handle;
|
| 505 |
+
}
|
| 506 |
+
|
| 507 |
+
static zk_t *_zk_get_handle_inner(pTHX_ Net__ZooKeeper attr_hash)
|
| 508 |
+
{
|
| 509 |
+
zk_handle_t *handle;
|
| 510 |
+
|
| 511 |
+
handle = _zk_check_handle_inner(aTHX_ attr_hash, PACKAGE_SIGNATURE);
|
| 512 |
+
|
| 513 |
+
return handle ? handle->handle.zk : NULL;
|
| 514 |
+
}
|
| 515 |
+
|
| 516 |
+
static zk_t *_zk_get_handle_outer(pTHX_ Net__ZooKeeper zkh)
|
| 517 |
+
{
|
| 518 |
+
zk_handle_t *handle;
|
| 519 |
+
|
| 520 |
+
handle = _zk_check_handle_outer(aTHX_ zkh, NULL, PACKAGE_NAME,
|
| 521 |
+
PACKAGE_SIGNATURE);
|
| 522 |
+
|
| 523 |
+
return handle ? handle->handle.zk : NULL;
|
| 524 |
+
}
|
| 525 |
+
|
| 526 |
+
static zk_stat_t *_zks_get_handle_inner(pTHX_ Net__ZooKeeper__Stat attr_hash)
|
| 527 |
+
{
|
| 528 |
+
zk_handle_t *handle;
|
| 529 |
+
|
| 530 |
+
handle = _zk_check_handle_inner(aTHX_ attr_hash, STAT_PACKAGE_SIGNATURE);
|
| 531 |
+
|
| 532 |
+
return handle ? handle->handle.stat : NULL;
|
| 533 |
+
}
|
| 534 |
+
|
| 535 |
+
static zk_stat_t *_zks_get_handle_outer(pTHX_ Net__ZooKeeper__Stat zksh)
|
| 536 |
+
{
|
| 537 |
+
zk_handle_t *handle;
|
| 538 |
+
|
| 539 |
+
handle = _zk_check_handle_outer(aTHX_ zksh, NULL, STAT_PACKAGE_NAME,
|
| 540 |
+
STAT_PACKAGE_SIGNATURE);
|
| 541 |
+
|
| 542 |
+
return handle ? handle->handle.stat : NULL;
|
| 543 |
+
}
|
| 544 |
+
|
| 545 |
+
static zk_watch_t *_zkw_get_handle_inner(pTHX_ Net__ZooKeeper__Watch attr_hash)
|
| 546 |
+
{
|
| 547 |
+
zk_handle_t *handle;
|
| 548 |
+
|
| 549 |
+
handle = _zk_check_handle_inner(aTHX_ attr_hash, WATCH_PACKAGE_SIGNATURE);
|
| 550 |
+
|
| 551 |
+
return handle ? handle->handle.watch : NULL;
|
| 552 |
+
}
|
| 553 |
+
|
| 554 |
+
static zk_watch_t *_zkw_get_handle_outer(pTHX_ Net__ZooKeeper__Watch zkwh,
|
| 555 |
+
zk_handle_t **handle_ptr)
|
| 556 |
+
{
|
| 557 |
+
zk_handle_t *handle;
|
| 558 |
+
|
| 559 |
+
handle = _zk_check_handle_outer(aTHX_ zkwh, NULL, WATCH_PACKAGE_NAME,
|
| 560 |
+
WATCH_PACKAGE_SIGNATURE);
|
| 561 |
+
|
| 562 |
+
if (handle_ptr) {
|
| 563 |
+
*handle_ptr = handle;
|
| 564 |
+
}
|
| 565 |
+
|
| 566 |
+
return handle ? handle->handle.watch : NULL;
|
| 567 |
+
}
|
| 568 |
+
|
| 569 |
+
|
| 570 |
+
MODULE = Net::ZooKeeper PACKAGE = Net::ZooKeeper PREFIX = zk_
|
| 571 |
+
|
| 572 |
+
REQUIRE: 1.9508
|
| 573 |
+
|
| 574 |
+
PROTOTYPES: ENABLE
|
| 575 |
+
|
| 576 |
+
BOOT:
|
| 577 |
+
{
|
| 578 |
+
int i;
|
| 579 |
+
|
| 580 |
+
for (i = 0; i < NUM_ACL_ENTRY_KEYS; ++i) {
|
| 581 |
+
zk_key_t *key = &zk_acl_entry_keys[i];
|
| 582 |
+
|
| 583 |
+
key->name_len = strlen(key->name);
|
| 584 |
+
PERL_HASH(key->hash, key->name, key->name_len);
|
| 585 |
+
}
|
| 586 |
+
|
| 587 |
+
for (i = 0; i < NUM_KEYS; ++i) {
|
| 588 |
+
zk_keys[i].name_len = strlen(zk_keys[i].name);
|
| 589 |
+
}
|
| 590 |
+
|
| 591 |
+
for (i = 0; i < NUM_STAT_KEYS; ++i) {
|
| 592 |
+
zk_stat_keys[i].name_len = strlen(zk_stat_keys[i].name);
|
| 593 |
+
}
|
| 594 |
+
|
| 595 |
+
for (i = 0; i < NUM_WATCH_KEYS; ++i) {
|
| 596 |
+
zk_watch_keys[i].name_len = strlen(zk_watch_keys[i].name);
|
| 597 |
+
}
|
| 598 |
+
|
| 599 |
+
zoo_set_log_stream(NULL);
|
| 600 |
+
zoo_set_debug_level(0);
|
| 601 |
+
}
|
| 602 |
+
|
| 603 |
+
|
| 604 |
+
I32
|
| 605 |
+
zk_constant(alias=Nullch)
|
| 606 |
+
char *alias
|
| 607 |
+
ALIAS:
|
| 608 |
+
ZOK = ZOK
|
| 609 |
+
ZSYSTEMERROR = ZSYSTEMERROR
|
| 610 |
+
ZRUNTIMEINCONSISTENCY = ZRUNTIMEINCONSISTENCY
|
| 611 |
+
ZDATAINCONSISTENCY = ZDATAINCONSISTENCY
|
| 612 |
+
ZCONNECTIONLOSS = ZCONNECTIONLOSS
|
| 613 |
+
ZMARSHALLINGERROR = ZMARSHALLINGERROR
|
| 614 |
+
ZUNIMPLEMENTED = ZUNIMPLEMENTED
|
| 615 |
+
ZOPERATIONTIMEOUT = ZOPERATIONTIMEOUT
|
| 616 |
+
ZBADARGUMENTS = ZBADARGUMENTS
|
| 617 |
+
ZINVALIDSTATE = ZINVALIDSTATE
|
| 618 |
+
ZAPIERROR = ZAPIERROR
|
| 619 |
+
ZNONODE = ZNONODE
|
| 620 |
+
ZNOAUTH = ZNOAUTH
|
| 621 |
+
ZBADVERSION = ZBADVERSION
|
| 622 |
+
ZNOCHILDRENFOREPHEMERALS = ZNOCHILDRENFOREPHEMERALS
|
| 623 |
+
ZNODEEXISTS = ZNODEEXISTS
|
| 624 |
+
ZNOTEMPTY = ZNOTEMPTY
|
| 625 |
+
ZSESSIONEXPIRED = ZSESSIONEXPIRED
|
| 626 |
+
ZINVALIDCALLBACK = ZINVALIDCALLBACK
|
| 627 |
+
ZINVALIDACL = ZINVALIDACL
|
| 628 |
+
ZAUTHFAILED = ZAUTHFAILED
|
| 629 |
+
ZCLOSING = ZCLOSING
|
| 630 |
+
ZNOTHING = ZNOTHING
|
| 631 |
+
|
| 632 |
+
ZOO_EPHEMERAL = ZOO_EPHEMERAL
|
| 633 |
+
ZOO_SEQUENCE = ZOO_SEQUENCE
|
| 634 |
+
|
| 635 |
+
ZOO_PERM_READ = ZOO_PERM_READ
|
| 636 |
+
ZOO_PERM_WRITE = ZOO_PERM_WRITE
|
| 637 |
+
ZOO_PERM_CREATE = ZOO_PERM_CREATE
|
| 638 |
+
ZOO_PERM_DELETE = ZOO_PERM_DELETE
|
| 639 |
+
ZOO_PERM_ADMIN = ZOO_PERM_ADMIN
|
| 640 |
+
ZOO_PERM_ALL = ZOO_PERM_ALL
|
| 641 |
+
|
| 642 |
+
ZOO_CREATED_EVENT = ZOO_CREATED_EVENT
|
| 643 |
+
ZOO_DELETED_EVENT = ZOO_DELETED_EVENT
|
| 644 |
+
ZOO_CHANGED_EVENT = ZOO_CHANGED_EVENT
|
| 645 |
+
ZOO_CHILD_EVENT = ZOO_CHILD_EVENT
|
| 646 |
+
ZOO_SESSION_EVENT = ZOO_SESSION_EVENT
|
| 647 |
+
ZOO_NOTWATCHING_EVENT = ZOO_NOTWATCHING_EVENT
|
| 648 |
+
|
| 649 |
+
ZOO_EXPIRED_SESSION_STATE = ZOO_EXPIRED_SESSION_STATE
|
| 650 |
+
ZOO_AUTH_FAILED_STATE = ZOO_AUTH_FAILED_STATE
|
| 651 |
+
ZOO_CONNECTING_STATE = ZOO_CONNECTING_STATE
|
| 652 |
+
ZOO_ASSOCIATING_STATE = ZOO_ASSOCIATING_STATE
|
| 653 |
+
ZOO_CONNECTED_STATE = ZOO_CONNECTED_STATE
|
| 654 |
+
|
| 655 |
+
ZOO_LOG_LEVEL_OFF = ZOO_LOG_LEVEL_OFF
|
| 656 |
+
ZOO_LOG_LEVEL_ERROR = ZOO_LOG_LEVEL_ERROR
|
| 657 |
+
ZOO_LOG_LEVEL_WARN = ZOO_LOG_LEVEL_WARN
|
| 658 |
+
ZOO_LOG_LEVEL_INFO = ZOO_LOG_LEVEL_INFO
|
| 659 |
+
ZOO_LOG_LEVEL_DEBUG = ZOO_LOG_LEVEL_DEBUG
|
| 660 |
+
CODE:
|
| 661 |
+
if (!ix) {
|
| 662 |
+
if (!alias) {
|
| 663 |
+
alias = GvNAME(CvGV(cv));
|
| 664 |
+
}
|
| 665 |
+
|
| 666 |
+
if (strEQ(alias, "ZOK")) {
|
| 667 |
+
RETVAL = ZOK;
|
| 668 |
+
}
|
| 669 |
+
else if (strEQ(alias, "ZOO_LOG_LEVEL_OFF")) {
|
| 670 |
+
RETVAL = ZOO_LOG_LEVEL_OFF;
|
| 671 |
+
}
|
| 672 |
+
else {
|
| 673 |
+
Perl_croak(aTHX_ "unknown " PACKAGE_NAME " constant: %s",
|
| 674 |
+
alias);
|
| 675 |
+
}
|
| 676 |
+
}
|
| 677 |
+
else {
|
| 678 |
+
RETVAL = ix;
|
| 679 |
+
}
|
| 680 |
+
OUTPUT:
|
| 681 |
+
RETVAL
|
| 682 |
+
|
| 683 |
+
|
| 684 |
+
AV *
|
| 685 |
+
zk_acl_constant(alias=Nullch)
|
| 686 |
+
char *alias
|
| 687 |
+
ALIAS:
|
| 688 |
+
ZOO_OPEN_ACL_UNSAFE = 1
|
| 689 |
+
ZOO_READ_ACL_UNSAFE = 2
|
| 690 |
+
ZOO_CREATOR_ALL_ACL = 3
|
| 691 |
+
PREINIT:
|
| 692 |
+
struct ACL_vector acl;
|
| 693 |
+
AV *acl_arr;
|
| 694 |
+
int i;
|
| 695 |
+
PPCODE:
|
| 696 |
+
if (!ix && !alias) {
|
| 697 |
+
alias = GvNAME(CvGV(cv));
|
| 698 |
+
}
|
| 699 |
+
|
| 700 |
+
if (ix == 1 || (alias != NULL && strEQ(alias, "ZOO_OPEN_ACL_UNSAFE"))) {
|
| 701 |
+
acl = ZOO_OPEN_ACL_UNSAFE;
|
| 702 |
+
}
|
| 703 |
+
else if (ix == 2 || (alias != NULL && strEQ(alias, "ZOO_READ_ACL_UNSAFE"))) {
|
| 704 |
+
acl = ZOO_READ_ACL_UNSAFE;
|
| 705 |
+
}
|
| 706 |
+
else if (ix == 3 || (alias != NULL && strEQ(alias, "ZOO_CREATOR_ALL_ACL"))) {
|
| 707 |
+
acl = ZOO_CREATOR_ALL_ACL;
|
| 708 |
+
}
|
| 709 |
+
else {
|
| 710 |
+
Perl_croak(aTHX_ "unknown " PACKAGE_NAME " constant: %s", alias);
|
| 711 |
+
}
|
| 712 |
+
|
| 713 |
+
acl_arr = newAV();
|
| 714 |
+
|
| 715 |
+
av_extend(acl_arr, acl.count);
|
| 716 |
+
|
| 717 |
+
for (i = 0; i < acl.count; ++i) {
|
| 718 |
+
HV *acl_entry_hash = newHV();
|
| 719 |
+
SV *val;
|
| 720 |
+
|
| 721 |
+
_zk_fill_acl_entry_hash(aTHX_ &acl.data[i], acl_entry_hash);
|
| 722 |
+
|
| 723 |
+
val = newRV_noinc((SV*) acl_entry_hash);
|
| 724 |
+
|
| 725 |
+
if (!av_store(acl_arr, i, val)) {
|
| 726 |
+
SvREFCNT_dec(val);
|
| 727 |
+
}
|
| 728 |
+
}
|
| 729 |
+
|
| 730 |
+
ST(0) = sv_2mortal(newRV_noinc((SV*) acl_arr));
|
| 731 |
+
|
| 732 |
+
XSRETURN(1);
|
| 733 |
+
|
| 734 |
+
|
| 735 |
+
void
|
| 736 |
+
zk_set_log_level(level)
|
| 737 |
+
int level
|
| 738 |
+
PPCODE:
|
| 739 |
+
if (level < ZOO_LOG_LEVEL_OFF || level > ZOO_LOG_LEVEL_DEBUG) {
|
| 740 |
+
Perl_croak(aTHX_ "invalid log level: %d", level);
|
| 741 |
+
}
|
| 742 |
+
|
| 743 |
+
zoo_set_debug_level(level);
|
| 744 |
+
|
| 745 |
+
XSRETURN_EMPTY;
|
| 746 |
+
|
| 747 |
+
|
| 748 |
+
void
|
| 749 |
+
zk_set_deterministic_conn_order(flag)
|
| 750 |
+
bool flag
|
| 751 |
+
PPCODE:
|
| 752 |
+
zoo_deterministic_conn_order(!!flag);
|
| 753 |
+
|
| 754 |
+
XSRETURN_EMPTY;
|
| 755 |
+
|
| 756 |
+
|
| 757 |
+
void
|
| 758 |
+
zk_new(package, hosts, ...)
|
| 759 |
+
char *package
|
| 760 |
+
char *hosts
|
| 761 |
+
PREINIT:
|
| 762 |
+
int recv_timeout = DEFAULT_RECV_TIMEOUT_MSEC;
|
| 763 |
+
#ifdef HAVE_CYRUS_SASL_H
|
| 764 |
+
zoo_sasl_params_t sasl_params = { 0 };
|
| 765 |
+
const char *sasl_user = NULL;
|
| 766 |
+
const char *sasl_realm = NULL;
|
| 767 |
+
const char *sasl_password_file = NULL;
|
| 768 |
+
int use_sasl = 0;
|
| 769 |
+
#endif /* HAVE_CYRUS_SASL_H */
|
| 770 |
+
const clientid_t *client_id = NULL;
|
| 771 |
+
zk_t *zk;
|
| 772 |
+
zk_handle_t *handle;
|
| 773 |
+
HV *stash, *zk_hash, *attr_hash;
|
| 774 |
+
SV *attr;
|
| 775 |
+
int i;
|
| 776 |
+
PPCODE:
|
| 777 |
+
if (items > 2 && items % 2) {
|
| 778 |
+
Perl_croak(aTHX_ "invalid number of arguments");
|
| 779 |
+
}
|
| 780 |
+
|
| 781 |
+
for (i = 2; i < items; i += 2) {
|
| 782 |
+
char *key = SvPV_nolen(ST(i));
|
| 783 |
+
|
| 784 |
+
if (strcaseEQ(key, "session_timeout")) {
|
| 785 |
+
recv_timeout = SvIV(ST(i + 1));
|
| 786 |
+
|
| 787 |
+
/* NOTE: would be nice if requirement in zookeeper_interest()
|
| 788 |
+
* that recv_timeout*2 be non-negative was documented
|
| 789 |
+
*/
|
| 790 |
+
if (recv_timeout < 0 || recv_timeout > (PERL_INT_MAX >> 1)) {
|
| 791 |
+
Perl_croak(aTHX_ "invalid session timeout: %d",
|
| 792 |
+
recv_timeout);
|
| 793 |
+
}
|
| 794 |
+
}
|
| 795 |
+
else if (strcaseEQ(key, "session_id")) {
|
| 796 |
+
STRLEN client_id_len;
|
| 797 |
+
|
| 798 |
+
client_id = (const clientid_t*) SvPV(ST(i + 1), client_id_len);
|
| 799 |
+
|
| 800 |
+
if (client_id_len != sizeof(clientid_t)) {
|
| 801 |
+
Perl_croak(aTHX_ "invalid session ID");
|
| 802 |
+
}
|
| 803 |
+
}
|
| 804 |
+
#ifdef HAVE_CYRUS_SASL_H
|
| 805 |
+
else if (strcaseEQ(key, "sasl_options")) {
|
| 806 |
+
SV *hash_sv = ST(i + 1);
|
| 807 |
+
HV *hash;
|
| 808 |
+
char *key;
|
| 809 |
+
I32 key_length;
|
| 810 |
+
SV *value;
|
| 811 |
+
|
| 812 |
+
if (!SvROK(hash_sv) || SvTYPE(SvRV(hash_sv)) != SVt_PVHV) {
|
| 813 |
+
Perl_croak(aTHX_ "sasl_options requires a hash reference");
|
| 814 |
+
}
|
| 815 |
+
|
| 816 |
+
hash = (HV *)SvRV(hash_sv);
|
| 817 |
+
hv_iterinit(hash);
|
| 818 |
+
while ((value = hv_iternextsv(hash, &key, &key_length))) {
|
| 819 |
+
if (strcaseEQ(key, "service")) {
|
| 820 |
+
sasl_params.service = SvPV_nolen(value);
|
| 821 |
+
}
|
| 822 |
+
else if (strcaseEQ(key, "host")) {
|
| 823 |
+
sasl_params.host = SvPV_nolen(value);
|
| 824 |
+
}
|
| 825 |
+
else if (strcaseEQ(key, "mechlist")) {
|
| 826 |
+
sasl_params.mechlist = SvPV_nolen(value);
|
| 827 |
+
}
|
| 828 |
+
else if (strcaseEQ(key, "user")) {
|
| 829 |
+
sasl_user = SvPV_nolen(value);
|
| 830 |
+
}
|
| 831 |
+
else if (strcaseEQ(key, "realm")) {
|
| 832 |
+
sasl_realm = SvPV_nolen(value);
|
| 833 |
+
}
|
| 834 |
+
else if (strcaseEQ(key, "password_file")) {
|
| 835 |
+
sasl_password_file = SvPV_nolen(value);
|
| 836 |
+
}
|
| 837 |
+
}
|
| 838 |
+
use_sasl = 1;
|
| 839 |
+
}
|
| 840 |
+
#endif /* HAVE_CYRUS_SASL_H */
|
| 841 |
+
}
|
| 842 |
+
|
| 843 |
+
Newxz(zk, 1, zk_t);
|
| 844 |
+
#ifdef HAVE_CYRUS_SASL_H
|
| 845 |
+
if (use_sasl) {
|
| 846 |
+
/* KLUDGE: Leaks a reference count. Authen::SASL::XS does
|
| 847 |
+
the same, though. TODO(ddiederen): Fix. */
|
| 848 |
+
sasl_client_init(NULL);
|
| 849 |
+
sasl_params.callbacks = zoo_sasl_make_basic_callbacks(sasl_user,
|
| 850 |
+
sasl_realm, sasl_password_file);
|
| 851 |
+
}
|
| 852 |
+
|
| 853 |
+
zk->handle = zookeeper_init_sasl(hosts, NULL, recv_timeout,
|
| 854 |
+
client_id, NULL, 0, NULL, use_sasl ? &sasl_params : NULL);
|
| 855 |
+
#else
|
| 856 |
+
zk->handle = zookeeper_init(hosts, NULL, recv_timeout,
|
| 857 |
+
client_id, NULL, 0);
|
| 858 |
+
#endif /* HAVE_CYRUS_SASL_H */
|
| 859 |
+
|
| 860 |
+
if (!zk->handle) {
|
| 861 |
+
Safefree(zk);
|
| 862 |
+
|
| 863 |
+
XSRETURN_UNDEF;
|
| 864 |
+
}
|
| 865 |
+
|
| 866 |
+
Newxz(zk->first_watch, 1, zk_watch_t);
|
| 867 |
+
|
| 868 |
+
zk->data_buf_len = DEFAULT_DATA_BUF_LEN;
|
| 869 |
+
zk->path_buf_len = DEFAULT_PATH_BUF_LEN;
|
| 870 |
+
zk->watch_timeout = DEFAULT_WATCH_TIMEOUT;
|
| 871 |
+
|
| 872 |
+
zk->hosts_len = strlen(hosts);
|
| 873 |
+
zk->hosts = savepvn(hosts, zk->hosts_len);
|
| 874 |
+
|
| 875 |
+
Newx(handle, 1, zk_handle_t);
|
| 876 |
+
|
| 877 |
+
handle->signature = PACKAGE_SIGNATURE;
|
| 878 |
+
handle->handle.zk = zk;
|
| 879 |
+
|
| 880 |
+
/* We use several tricks from DBI here. The attr_hash is our
|
| 881 |
+
* empty inner hash; we attach extra magic to it in the form of
|
| 882 |
+
* our zk_handle_t structure. Then we tie attr_hash to zk_hash,
|
| 883 |
+
* our outer hash. This is what is passed around (by reference) by
|
| 884 |
+
* callers.
|
| 885 |
+
*
|
| 886 |
+
* Most methods use _zk_get_handle_outer() which finds our inner
|
| 887 |
+
* handle, then returns the zk_t structure from its extra magic
|
| 888 |
+
* pointer.
|
| 889 |
+
*
|
| 890 |
+
* However, the tied hash methods, FETCH(), STORE(), and so forth,
|
| 891 |
+
* receive an already-dereferenced inner handle hash. This is
|
| 892 |
+
* because we bless both inner and outer handles into this class,
|
| 893 |
+
* so when a caller's code references a hash element in our
|
| 894 |
+
* outer handle, Perl detects its tied magic, looks up the
|
| 895 |
+
* tied object (our inner handle) and invokes the tied hash methods
|
| 896 |
+
* in its class on it. Since we blessed it into the same class
|
| 897 |
+
* as the outer handle, these methods simply reside in our package.
|
| 898 |
+
*/
|
| 899 |
+
|
| 900 |
+
stash = gv_stashpv(package, GV_ADDWARN);
|
| 901 |
+
|
| 902 |
+
attr_hash = newHV();
|
| 903 |
+
|
| 904 |
+
sv_magic((SV*) attr_hash, Nullsv, PERL_MAGIC_ext,
|
| 905 |
+
(const char*) handle, 0);
|
| 906 |
+
|
| 907 |
+
attr = sv_bless(newRV_noinc((SV*) attr_hash), stash);
|
| 908 |
+
|
| 909 |
+
zk_hash = newHV();
|
| 910 |
+
|
| 911 |
+
sv_magic((SV*) zk_hash, attr, PERL_MAGIC_tied, Nullch, 0);
|
| 912 |
+
SvREFCNT_dec(attr);
|
| 913 |
+
|
| 914 |
+
ST(0) = sv_bless(sv_2mortal(newRV_noinc((SV*) zk_hash)), stash);
|
| 915 |
+
|
| 916 |
+
XSRETURN(1);
|
| 917 |
+
|
| 918 |
+
|
| 919 |
+
void
|
| 920 |
+
zk_DESTROY(zkh)
|
| 921 |
+
Net::ZooKeeper zkh
|
| 922 |
+
PREINIT:
|
| 923 |
+
zk_handle_t *handle;
|
| 924 |
+
HV *attr_hash;
|
| 925 |
+
int ret = ZBADARGUMENTS;
|
| 926 |
+
PPCODE:
|
| 927 |
+
handle = _zk_check_handle_outer(aTHX_ zkh, &attr_hash,
|
| 928 |
+
PACKAGE_NAME, PACKAGE_SIGNATURE);
|
| 929 |
+
|
| 930 |
+
if (!handle) {
|
| 931 |
+
handle = _zk_check_handle_inner(aTHX_ zkh, PACKAGE_SIGNATURE);
|
| 932 |
+
|
| 933 |
+
if (handle) {
|
| 934 |
+
attr_hash = zkh;
|
| 935 |
+
zkh = NULL;
|
| 936 |
+
}
|
| 937 |
+
}
|
| 938 |
+
|
| 939 |
+
if (handle) {
|
| 940 |
+
zk_t *zk = handle->handle.zk;
|
| 941 |
+
|
| 942 |
+
ret = zookeeper_close(zk->handle);
|
| 943 |
+
|
| 944 |
+
/* detach all now-inactive watches still tied to handles */
|
| 945 |
+
_zk_release_watches(aTHX_ zk->first_watch, 1);
|
| 946 |
+
|
| 947 |
+
Safefree(zk->first_watch);
|
| 948 |
+
Safefree(zk->hosts);
|
| 949 |
+
Safefree(zk);
|
| 950 |
+
Safefree(handle);
|
| 951 |
+
|
| 952 |
+
sv_unmagic((SV*) attr_hash, PERL_MAGIC_ext);
|
| 953 |
+
}
|
| 954 |
+
|
| 955 |
+
if (zkh && attr_hash) {
|
| 956 |
+
sv_unmagic((SV*) zkh, PERL_MAGIC_tied);
|
| 957 |
+
}
|
| 958 |
+
|
| 959 |
+
if (GIMME_V == G_VOID) {
|
| 960 |
+
XSRETURN_EMPTY;
|
| 961 |
+
}
|
| 962 |
+
else if (ret == ZOK) {
|
| 963 |
+
XSRETURN_YES;
|
| 964 |
+
}
|
| 965 |
+
else {
|
| 966 |
+
XSRETURN_NO;
|
| 967 |
+
}
|
| 968 |
+
|
| 969 |
+
|
| 970 |
+
void
|
| 971 |
+
zk_CLONE(package)
|
| 972 |
+
char *package
|
| 973 |
+
PPCODE:
|
| 974 |
+
XSRETURN_EMPTY;
|
| 975 |
+
|
| 976 |
+
|
| 977 |
+
void
|
| 978 |
+
zk_CLONE_SKIP(package)
|
| 979 |
+
char *package
|
| 980 |
+
PPCODE:
|
| 981 |
+
XSRETURN_YES;
|
| 982 |
+
|
| 983 |
+
|
| 984 |
+
void
|
| 985 |
+
zk_TIEHASH(package, ...)
|
| 986 |
+
char *package
|
| 987 |
+
PPCODE:
|
| 988 |
+
Perl_croak(aTHX_ "tying hashes of class "
|
| 989 |
+
PACKAGE_NAME " not supported");
|
| 990 |
+
|
| 991 |
+
|
| 992 |
+
void
|
| 993 |
+
zk_UNTIE(attr_hash, ref_count)
|
| 994 |
+
Net::ZooKeeper attr_hash
|
| 995 |
+
IV ref_count
|
| 996 |
+
PPCODE:
|
| 997 |
+
Perl_croak(aTHX_ "untying hashes of class "
|
| 998 |
+
PACKAGE_NAME " not supported");
|
| 999 |
+
|
| 1000 |
+
|
| 1001 |
+
void
|
| 1002 |
+
zk_FIRSTKEY(attr_hash)
|
| 1003 |
+
Net::ZooKeeper attr_hash
|
| 1004 |
+
PREINIT:
|
| 1005 |
+
zk_t *zk;
|
| 1006 |
+
PPCODE:
|
| 1007 |
+
zk = _zk_get_handle_inner(aTHX_ attr_hash);
|
| 1008 |
+
|
| 1009 |
+
if (!zk) {
|
| 1010 |
+
Perl_croak(aTHX_ "invalid handle");
|
| 1011 |
+
}
|
| 1012 |
+
|
| 1013 |
+
ST(0) = sv_2mortal(newSVpvn(zk_keys[0].name, zk_keys[0].name_len));
|
| 1014 |
+
|
| 1015 |
+
XSRETURN(1);
|
| 1016 |
+
|
| 1017 |
+
|
| 1018 |
+
void
|
| 1019 |
+
zk_NEXTKEY(attr_hash, attr_key)
|
| 1020 |
+
Net::ZooKeeper attr_hash
|
| 1021 |
+
SV *attr_key
|
| 1022 |
+
PREINIT:
|
| 1023 |
+
zk_t *zk;
|
| 1024 |
+
char *key;
|
| 1025 |
+
int i;
|
| 1026 |
+
PPCODE:
|
| 1027 |
+
zk = _zk_get_handle_inner(aTHX_ attr_hash);
|
| 1028 |
+
|
| 1029 |
+
if (!zk) {
|
| 1030 |
+
Perl_croak(aTHX_ "invalid handle");
|
| 1031 |
+
}
|
| 1032 |
+
|
| 1033 |
+
key = SvPV_nolen(attr_key);
|
| 1034 |
+
|
| 1035 |
+
for (i = 0; i < NUM_KEYS; ++i) {
|
| 1036 |
+
if (strcaseEQ(key, zk_keys[i].name)) {
|
| 1037 |
+
++i;
|
| 1038 |
+
|
| 1039 |
+
break;
|
| 1040 |
+
}
|
| 1041 |
+
}
|
| 1042 |
+
|
| 1043 |
+
if (i < NUM_KEYS) {
|
| 1044 |
+
ST(0) = sv_2mortal(newSVpvn(zk_keys[i].name, zk_keys[i].name_len));
|
| 1045 |
+
|
| 1046 |
+
XSRETURN(1);
|
| 1047 |
+
}
|
| 1048 |
+
else {
|
| 1049 |
+
XSRETURN_EMPTY;
|
| 1050 |
+
}
|
| 1051 |
+
|
| 1052 |
+
|
| 1053 |
+
void
|
| 1054 |
+
zk_SCALAR(attr_hash)
|
| 1055 |
+
Net::ZooKeeper attr_hash
|
| 1056 |
+
PPCODE:
|
| 1057 |
+
XSRETURN_YES;
|
| 1058 |
+
|
| 1059 |
+
|
| 1060 |
+
void
|
| 1061 |
+
zk_FETCH(attr_hash, attr_key)
|
| 1062 |
+
Net::ZooKeeper attr_hash
|
| 1063 |
+
SV *attr_key
|
| 1064 |
+
PREINIT:
|
| 1065 |
+
zk_t *zk;
|
| 1066 |
+
char *key;
|
| 1067 |
+
SV *val = NULL;
|
| 1068 |
+
PPCODE:
|
| 1069 |
+
zk = _zk_get_handle_inner(aTHX_ attr_hash);
|
| 1070 |
+
|
| 1071 |
+
if (!zk) {
|
| 1072 |
+
Perl_croak(aTHX_ "invalid handle");
|
| 1073 |
+
}
|
| 1074 |
+
|
| 1075 |
+
key = SvPV_nolen(attr_key);
|
| 1076 |
+
|
| 1077 |
+
if (strcaseEQ(key, "data_read_len")) {
|
| 1078 |
+
val = newSViv(zk->data_buf_len);
|
| 1079 |
+
}
|
| 1080 |
+
else if (strcaseEQ(key, "path_read_len")) {
|
| 1081 |
+
val = newSViv(zk->path_buf_len);
|
| 1082 |
+
}
|
| 1083 |
+
else if (strcaseEQ(key, "watch_timeout")) {
|
| 1084 |
+
val = newSVuv(zk->watch_timeout);
|
| 1085 |
+
}
|
| 1086 |
+
else if (strcaseEQ(key, "hosts")) {
|
| 1087 |
+
val = newSVpvn(zk->hosts, zk->hosts_len);
|
| 1088 |
+
}
|
| 1089 |
+
else if (strcaseEQ(key, "session_timeout")) {
|
| 1090 |
+
val = newSViv(zoo_recv_timeout(zk->handle));
|
| 1091 |
+
}
|
| 1092 |
+
else if (strcaseEQ(key, "session_id")) {
|
| 1093 |
+
const clientid_t *client_id;
|
| 1094 |
+
clientid_t null_client_id;
|
| 1095 |
+
|
| 1096 |
+
client_id = zoo_client_id(zk->handle);
|
| 1097 |
+
|
| 1098 |
+
memset(&null_client_id, 0, sizeof(clientid_t));
|
| 1099 |
+
|
| 1100 |
+
if (!memcmp(client_id, &null_client_id, sizeof(clientid_t))) {
|
| 1101 |
+
val = newSVpv("", 0);
|
| 1102 |
+
}
|
| 1103 |
+
else {
|
| 1104 |
+
val = newSVpvn((const char*) client_id, sizeof(clientid_t));
|
| 1105 |
+
}
|
| 1106 |
+
}
|
| 1107 |
+
else if (strcaseEQ(key, "pending_watches")) {
|
| 1108 |
+
/* cleanup any completed watches not tied to a handle */
|
| 1109 |
+
val = newSVuv(_zk_release_watches(aTHX_ zk->first_watch, 0));
|
| 1110 |
+
}
|
| 1111 |
+
|
| 1112 |
+
if (val) {
|
| 1113 |
+
ST(0) = sv_2mortal(val);
|
| 1114 |
+
|
| 1115 |
+
XSRETURN(1);
|
| 1116 |
+
}
|
| 1117 |
+
|
| 1118 |
+
Perl_warn(aTHX_ "invalid element: %s", key);
|
| 1119 |
+
|
| 1120 |
+
XSRETURN_UNDEF;
|
| 1121 |
+
|
| 1122 |
+
|
| 1123 |
+
void
|
| 1124 |
+
zk_STORE(attr_hash, attr_key, attr_val)
|
| 1125 |
+
Net::ZooKeeper attr_hash
|
| 1126 |
+
SV *attr_key
|
| 1127 |
+
SV *attr_val
|
| 1128 |
+
PREINIT:
|
| 1129 |
+
zk_t *zk;
|
| 1130 |
+
char *key;
|
| 1131 |
+
PPCODE:
|
| 1132 |
+
zk = _zk_get_handle_inner(aTHX_ attr_hash);
|
| 1133 |
+
|
| 1134 |
+
if (!zk) {
|
| 1135 |
+
Perl_croak(aTHX_ "invalid handle");
|
| 1136 |
+
}
|
| 1137 |
+
|
| 1138 |
+
key = SvPV_nolen(attr_key);
|
| 1139 |
+
|
| 1140 |
+
if (strcaseEQ(key, "data_read_len")) {
|
| 1141 |
+
int val = SvIV(attr_val);
|
| 1142 |
+
|
| 1143 |
+
if (val < 0) {
|
| 1144 |
+
Perl_croak(aTHX_ "invalid data read length: %d", val);
|
| 1145 |
+
}
|
| 1146 |
+
|
| 1147 |
+
zk->data_buf_len = val;
|
| 1148 |
+
}
|
| 1149 |
+
else if (strcaseEQ(key, "path_read_len")) {
|
| 1150 |
+
int val = SvIV(attr_val);
|
| 1151 |
+
|
| 1152 |
+
if (val < 0) {
|
| 1153 |
+
Perl_croak(aTHX_ "invalid path read length: %d", val);
|
| 1154 |
+
}
|
| 1155 |
+
|
| 1156 |
+
zk->path_buf_len = val;
|
| 1157 |
+
}
|
| 1158 |
+
else if (strcaseEQ(key, "watch_timeout")) {
|
| 1159 |
+
zk->watch_timeout = SvUV(attr_val);
|
| 1160 |
+
}
|
| 1161 |
+
else {
|
| 1162 |
+
int i;
|
| 1163 |
+
|
| 1164 |
+
for (i = 0; i < NUM_KEYS; ++i) {
|
| 1165 |
+
if (strcaseEQ(key, zk_keys[i].name)) {
|
| 1166 |
+
Perl_warn(aTHX_ "read-only element: %s", key);
|
| 1167 |
+
|
| 1168 |
+
XSRETURN_EMPTY;
|
| 1169 |
+
}
|
| 1170 |
+
}
|
| 1171 |
+
|
| 1172 |
+
Perl_warn(aTHX_ "invalid element: %s", key);
|
| 1173 |
+
}
|
| 1174 |
+
|
| 1175 |
+
XSRETURN_EMPTY;
|
| 1176 |
+
|
| 1177 |
+
|
| 1178 |
+
void
|
| 1179 |
+
zk_EXISTS(attr_hash, attr_key)
|
| 1180 |
+
Net::ZooKeeper attr_hash
|
| 1181 |
+
SV *attr_key
|
| 1182 |
+
PREINIT:
|
| 1183 |
+
zk_t *zk;
|
| 1184 |
+
char *key;
|
| 1185 |
+
int i;
|
| 1186 |
+
PPCODE:
|
| 1187 |
+
zk = _zk_get_handle_inner(aTHX_ attr_hash);
|
| 1188 |
+
|
| 1189 |
+
if (!zk) {
|
| 1190 |
+
Perl_croak(aTHX_ "invalid handle");
|
| 1191 |
+
}
|
| 1192 |
+
|
| 1193 |
+
key = SvPV_nolen(attr_key);
|
| 1194 |
+
|
| 1195 |
+
for (i = 0; i < NUM_KEYS; ++i) {
|
| 1196 |
+
if (strcaseEQ(key, zk_keys[i].name)) {
|
| 1197 |
+
XSRETURN_YES;
|
| 1198 |
+
}
|
| 1199 |
+
}
|
| 1200 |
+
|
| 1201 |
+
XSRETURN_NO;
|
| 1202 |
+
|
| 1203 |
+
|
| 1204 |
+
void
|
| 1205 |
+
zk_DELETE(attr_hash, attr_key)
|
| 1206 |
+
Net::ZooKeeper attr_hash
|
| 1207 |
+
SV *attr_key
|
| 1208 |
+
PPCODE:
|
| 1209 |
+
Perl_warn(aTHX_ "deleting elements from hashes of class "
|
| 1210 |
+
PACKAGE_NAME " not supported");
|
| 1211 |
+
|
| 1212 |
+
XSRETURN_EMPTY;
|
| 1213 |
+
|
| 1214 |
+
|
| 1215 |
+
void
|
| 1216 |
+
zk_CLEAR(attr_hash)
|
| 1217 |
+
Net::ZooKeeper attr_hash
|
| 1218 |
+
PPCODE:
|
| 1219 |
+
Perl_warn(aTHX_ "clearing hashes of class "
|
| 1220 |
+
PACKAGE_NAME " not supported");
|
| 1221 |
+
|
| 1222 |
+
XSRETURN_EMPTY;
|
| 1223 |
+
|
| 1224 |
+
|
| 1225 |
+
SV *
|
| 1226 |
+
zk_get_error(zkh)
|
| 1227 |
+
Net::ZooKeeper zkh
|
| 1228 |
+
PREINIT:
|
| 1229 |
+
zk_t *zk;
|
| 1230 |
+
CODE:
|
| 1231 |
+
zk = _zk_get_handle_outer(aTHX_ zkh);
|
| 1232 |
+
|
| 1233 |
+
if (!zk) {
|
| 1234 |
+
Perl_croak(aTHX_ "invalid handle");
|
| 1235 |
+
}
|
| 1236 |
+
|
| 1237 |
+
RETVAL = newSViv(zk->last_ret);
|
| 1238 |
+
errno = zk->last_errno;
|
| 1239 |
+
OUTPUT:
|
| 1240 |
+
RETVAL
|
| 1241 |
+
|
| 1242 |
+
|
| 1243 |
+
void
|
| 1244 |
+
zk_add_auth(zkh, scheme, cert)
|
| 1245 |
+
Net::ZooKeeper zkh
|
| 1246 |
+
char *scheme
|
| 1247 |
+
char *cert; cert = (char *) SvPV($arg, cert_len);
|
| 1248 |
+
PREINIT:
|
| 1249 |
+
zk_t *zk;
|
| 1250 |
+
STRLEN cert_len;
|
| 1251 |
+
zk_watch_t *watch;
|
| 1252 |
+
int ret;
|
| 1253 |
+
PPCODE:
|
| 1254 |
+
zk = _zk_get_handle_outer(aTHX_ zkh);
|
| 1255 |
+
|
| 1256 |
+
if (!zk) {
|
| 1257 |
+
Perl_croak(aTHX_ "invalid handle");
|
| 1258 |
+
}
|
| 1259 |
+
|
| 1260 |
+
zk->last_ret = ZOK;
|
| 1261 |
+
zk->last_errno = 0;
|
| 1262 |
+
|
| 1263 |
+
if (cert_len > PERL_INT_MAX) {
|
| 1264 |
+
Perl_croak(aTHX_ "invalid certificate length: %zu", cert_len);
|
| 1265 |
+
}
|
| 1266 |
+
|
| 1267 |
+
watch = _zk_create_watch(aTHX);
|
| 1268 |
+
|
| 1269 |
+
if (!watch) {
|
| 1270 |
+
/* errno will be set */
|
| 1271 |
+
zk->last_ret = ZSYSTEMERROR;
|
| 1272 |
+
zk->last_errno = errno;
|
| 1273 |
+
|
| 1274 |
+
XSRETURN_NO;
|
| 1275 |
+
}
|
| 1276 |
+
|
| 1277 |
+
errno = 0;
|
| 1278 |
+
ret = zoo_add_auth(zk->handle, scheme, cert, cert_len,
|
| 1279 |
+
_zk_auth_completion, watch);
|
| 1280 |
+
|
| 1281 |
+
zk->last_ret = ret;
|
| 1282 |
+
zk->last_errno = errno;
|
| 1283 |
+
|
| 1284 |
+
if (ret == ZOK) {
|
| 1285 |
+
pthread_mutex_lock(&watch->mutex);
|
| 1286 |
+
|
| 1287 |
+
while (!watch->done) {
|
| 1288 |
+
pthread_cond_wait(&watch->cond, &watch->mutex);
|
| 1289 |
+
}
|
| 1290 |
+
|
| 1291 |
+
pthread_mutex_unlock(&watch->mutex);
|
| 1292 |
+
|
| 1293 |
+
if (watch->done) {
|
| 1294 |
+
ret = watch->ret;
|
| 1295 |
+
}
|
| 1296 |
+
else {
|
| 1297 |
+
ret = ZINVALIDSTATE;
|
| 1298 |
+
}
|
| 1299 |
+
|
| 1300 |
+
/* errno may be set while we waited */
|
| 1301 |
+
zk->last_ret = ret;
|
| 1302 |
+
zk->last_errno = errno;
|
| 1303 |
+
}
|
| 1304 |
+
|
| 1305 |
+
_zk_destroy_watch(aTHX_ watch);
|
| 1306 |
+
|
| 1307 |
+
if (ret == ZOK) {
|
| 1308 |
+
XSRETURN_YES;
|
| 1309 |
+
}
|
| 1310 |
+
else {
|
| 1311 |
+
XSRETURN_NO;
|
| 1312 |
+
}
|
| 1313 |
+
|
| 1314 |
+
|
| 1315 |
+
void
|
| 1316 |
+
zk_create(zkh, path, buf, ...)
|
| 1317 |
+
Net::ZooKeeper zkh
|
| 1318 |
+
char *path
|
| 1319 |
+
char *buf; buf = (char *) SvPV($arg, buf_len);
|
| 1320 |
+
PREINIT:
|
| 1321 |
+
zk_t *zk;
|
| 1322 |
+
STRLEN buf_len;
|
| 1323 |
+
int flags = 0;
|
| 1324 |
+
char *path_buf;
|
| 1325 |
+
int path_buf_len;
|
| 1326 |
+
AV *acl_arr = NULL;
|
| 1327 |
+
struct ACL_vector acl;
|
| 1328 |
+
int i, ret;
|
| 1329 |
+
PPCODE:
|
| 1330 |
+
zk = _zk_get_handle_outer(aTHX_ zkh);
|
| 1331 |
+
|
| 1332 |
+
if (!zk) {
|
| 1333 |
+
Perl_croak(aTHX_ "invalid handle");
|
| 1334 |
+
}
|
| 1335 |
+
|
| 1336 |
+
zk->last_ret = ZOK;
|
| 1337 |
+
zk->last_errno = 0;
|
| 1338 |
+
|
| 1339 |
+
if (items > 3 && !(items % 2)) {
|
| 1340 |
+
Perl_croak(aTHX_ "invalid number of arguments");
|
| 1341 |
+
}
|
| 1342 |
+
|
| 1343 |
+
if (buf_len > PERL_INT_MAX) {
|
| 1344 |
+
Perl_croak(aTHX_ "invalid data length: %zu", buf_len);
|
| 1345 |
+
}
|
| 1346 |
+
|
| 1347 |
+
path_buf_len = zk->path_buf_len;
|
| 1348 |
+
|
| 1349 |
+
for (i = 3; i < items; i += 2) {
|
| 1350 |
+
char *key = SvPV_nolen(ST(i));
|
| 1351 |
+
|
| 1352 |
+
if (strcaseEQ(key, "path_read_len")) {
|
| 1353 |
+
path_buf_len = SvIV(ST(i + 1));
|
| 1354 |
+
|
| 1355 |
+
if (path_buf_len < 2) {
|
| 1356 |
+
Perl_croak(aTHX_ "invalid path read length: %d",
|
| 1357 |
+
path_buf_len);
|
| 1358 |
+
}
|
| 1359 |
+
}
|
| 1360 |
+
else if (strcaseEQ(key, "flags")) {
|
| 1361 |
+
flags = SvIV(ST(i + 1));
|
| 1362 |
+
|
| 1363 |
+
if (flags & ~(ZOO_SEQUENCE | ZOO_EPHEMERAL)) {
|
| 1364 |
+
Perl_croak(aTHX_ "invalid create flags: %d", flags);
|
| 1365 |
+
}
|
| 1366 |
+
}
|
| 1367 |
+
else if (strcaseEQ(key, "acl")) {
|
| 1368 |
+
const char *err;
|
| 1369 |
+
|
| 1370 |
+
if (!SvROK(ST(i + 1)) || SvTYPE(SvRV(ST(i + 1))) != SVt_PVAV) {
|
| 1371 |
+
Perl_croak(aTHX_ "invalid ACL array reference");
|
| 1372 |
+
}
|
| 1373 |
+
|
| 1374 |
+
acl_arr = (AV*) SvRV(ST(i + 1));
|
| 1375 |
+
|
| 1376 |
+
err = _zk_fill_acl(aTHX_ acl_arr, &acl);
|
| 1377 |
+
|
| 1378 |
+
if (err) {
|
| 1379 |
+
Perl_croak(aTHX_ "%s", err);
|
| 1380 |
+
}
|
| 1381 |
+
}
|
| 1382 |
+
}
|
| 1383 |
+
|
| 1384 |
+
/* NOTE: would be nice to be able to rely on null-terminated string */
|
| 1385 |
+
++path_buf_len;
|
| 1386 |
+
Newxz(path_buf, path_buf_len, char);
|
| 1387 |
+
|
| 1388 |
+
errno = 0;
|
| 1389 |
+
ret = zoo_create(zk->handle, path, buf, buf_len,
|
| 1390 |
+
(acl_arr ? &acl : NULL), flags,
|
| 1391 |
+
path_buf, path_buf_len);
|
| 1392 |
+
|
| 1393 |
+
zk->last_ret = ret;
|
| 1394 |
+
zk->last_errno = errno;
|
| 1395 |
+
|
| 1396 |
+
if (acl_arr) {
|
| 1397 |
+
_zk_free_acl(aTHX_ &acl);
|
| 1398 |
+
}
|
| 1399 |
+
|
| 1400 |
+
if (ret == ZOK) {
|
| 1401 |
+
ST(0) = sv_newmortal();
|
| 1402 |
+
#ifdef SV_HAS_TRAILING_NUL
|
| 1403 |
+
sv_usepvn_flags(ST(0), path_buf, strlen(path_buf),
|
| 1404 |
+
SV_HAS_TRAILING_NUL);
|
| 1405 |
+
#else
|
| 1406 |
+
sv_usepvn(ST(0), path_buf, strlen(path_buf));
|
| 1407 |
+
#endif
|
| 1408 |
+
SvCUR_set(ST(0), strlen(path_buf));
|
| 1409 |
+
|
| 1410 |
+
XSRETURN(1);
|
| 1411 |
+
}
|
| 1412 |
+
|
| 1413 |
+
Safefree(path_buf);
|
| 1414 |
+
|
| 1415 |
+
XSRETURN_UNDEF;
|
| 1416 |
+
|
| 1417 |
+
|
| 1418 |
+
void
|
| 1419 |
+
zk_delete(zkh, path, ...)
|
| 1420 |
+
Net::ZooKeeper zkh
|
| 1421 |
+
char *path
|
| 1422 |
+
PREINIT:
|
| 1423 |
+
zk_t *zk;
|
| 1424 |
+
int version = -1;
|
| 1425 |
+
int i, ret;
|
| 1426 |
+
PPCODE:
|
| 1427 |
+
zk = _zk_get_handle_outer(aTHX_ zkh);
|
| 1428 |
+
|
| 1429 |
+
if (!zk) {
|
| 1430 |
+
Perl_croak(aTHX_ "invalid handle");
|
| 1431 |
+
}
|
| 1432 |
+
|
| 1433 |
+
zk->last_ret = ZOK;
|
| 1434 |
+
zk->last_errno = 0;
|
| 1435 |
+
|
| 1436 |
+
if (items > 2 && items % 2) {
|
| 1437 |
+
Perl_croak(aTHX_ "invalid number of arguments");
|
| 1438 |
+
}
|
| 1439 |
+
|
| 1440 |
+
for (i = 2; i < items; i += 2) {
|
| 1441 |
+
char *key = SvPV_nolen(ST(i));
|
| 1442 |
+
|
| 1443 |
+
if (strcaseEQ(key, "version")) {
|
| 1444 |
+
version = SvIV(ST(i + 1));
|
| 1445 |
+
|
| 1446 |
+
if (version < 0) {
|
| 1447 |
+
Perl_croak(aTHX_ "invalid version requirement: %d",
|
| 1448 |
+
version);
|
| 1449 |
+
}
|
| 1450 |
+
}
|
| 1451 |
+
}
|
| 1452 |
+
|
| 1453 |
+
errno = 0;
|
| 1454 |
+
ret = zoo_delete(zk->handle, path, version);
|
| 1455 |
+
|
| 1456 |
+
zk->last_ret = ret;
|
| 1457 |
+
zk->last_errno = errno;
|
| 1458 |
+
|
| 1459 |
+
if (ret == ZOK) {
|
| 1460 |
+
XSRETURN_YES;
|
| 1461 |
+
}
|
| 1462 |
+
else {
|
| 1463 |
+
XSRETURN_NO;
|
| 1464 |
+
}
|
| 1465 |
+
|
| 1466 |
+
|
| 1467 |
+
void
|
| 1468 |
+
zk_exists(zkh, path, ...)
|
| 1469 |
+
Net::ZooKeeper zkh
|
| 1470 |
+
char *path
|
| 1471 |
+
PREINIT:
|
| 1472 |
+
zk_t *zk;
|
| 1473 |
+
zk_stat_t *stat = NULL;
|
| 1474 |
+
zk_watch_t *old_watch = NULL;
|
| 1475 |
+
zk_handle_t *watch_handle = NULL;
|
| 1476 |
+
watcher_fn watcher = NULL;
|
| 1477 |
+
zk_watch_t *new_watch = NULL;
|
| 1478 |
+
int i, ret;
|
| 1479 |
+
PPCODE:
|
| 1480 |
+
zk = _zk_get_handle_outer(aTHX_ zkh);
|
| 1481 |
+
|
| 1482 |
+
if (!zk) {
|
| 1483 |
+
Perl_croak(aTHX_ "invalid handle");
|
| 1484 |
+
}
|
| 1485 |
+
|
| 1486 |
+
zk->last_ret = ZOK;
|
| 1487 |
+
zk->last_errno = 0;
|
| 1488 |
+
|
| 1489 |
+
if (items > 2 && items % 2) {
|
| 1490 |
+
Perl_croak(aTHX_ "invalid number of arguments");
|
| 1491 |
+
}
|
| 1492 |
+
|
| 1493 |
+
for (i = 2; i < items; i += 2) {
|
| 1494 |
+
char *key = SvPV_nolen(ST(i));
|
| 1495 |
+
|
| 1496 |
+
if (strcaseEQ(key, "stat")) {
|
| 1497 |
+
if (!SvROK(ST(i + 1)) || SvTYPE(SvRV(ST(i + 1))) != SVt_PVHV ||
|
| 1498 |
+
!sv_derived_from(ST(i + 1), STAT_PACKAGE_NAME)) {
|
| 1499 |
+
Perl_croak(aTHX_ "stat is not a hash reference of "
|
| 1500 |
+
"type " STAT_PACKAGE_NAME);
|
| 1501 |
+
}
|
| 1502 |
+
|
| 1503 |
+
stat = _zks_get_handle_outer(aTHX_ (HV*) SvRV(ST(i + 1)));
|
| 1504 |
+
|
| 1505 |
+
if (!stat) {
|
| 1506 |
+
Perl_croak(aTHX_ "invalid stat handle");
|
| 1507 |
+
}
|
| 1508 |
+
}
|
| 1509 |
+
else if (strcaseEQ(key, "watch")) {
|
| 1510 |
+
if (!SvROK(ST(i + 1)) || SvTYPE(SvRV(ST(i + 1))) != SVt_PVHV ||
|
| 1511 |
+
!sv_derived_from(ST(i + 1), WATCH_PACKAGE_NAME)) {
|
| 1512 |
+
Perl_croak(aTHX_ "watch is not a hash reference of "
|
| 1513 |
+
"type " WATCH_PACKAGE_NAME);
|
| 1514 |
+
}
|
| 1515 |
+
|
| 1516 |
+
old_watch = _zkw_get_handle_outer(aTHX_ (HV*) SvRV(ST(i + 1)),
|
| 1517 |
+
&watch_handle);
|
| 1518 |
+
|
| 1519 |
+
if (!old_watch) {
|
| 1520 |
+
Perl_croak(aTHX_ "invalid watch handle");
|
| 1521 |
+
}
|
| 1522 |
+
}
|
| 1523 |
+
}
|
| 1524 |
+
|
| 1525 |
+
if (watch_handle) {
|
| 1526 |
+
new_watch = _zk_acquire_watch(aTHX);
|
| 1527 |
+
|
| 1528 |
+
if (!new_watch) {
|
| 1529 |
+
/* errno will be set */
|
| 1530 |
+
zk->last_ret = ZSYSTEMERROR;
|
| 1531 |
+
zk->last_errno = errno;
|
| 1532 |
+
|
| 1533 |
+
XSRETURN_NO;
|
| 1534 |
+
}
|
| 1535 |
+
|
| 1536 |
+
watcher = _zk_watcher;
|
| 1537 |
+
}
|
| 1538 |
+
|
| 1539 |
+
errno = 0;
|
| 1540 |
+
ret = zoo_wexists(zk->handle, path, watcher, new_watch, stat);
|
| 1541 |
+
|
| 1542 |
+
zk->last_ret = ret;
|
| 1543 |
+
zk->last_errno = errno;
|
| 1544 |
+
|
| 1545 |
+
if (watch_handle) {
|
| 1546 |
+
_zk_replace_watch(aTHX_ watch_handle, zk->first_watch,
|
| 1547 |
+
old_watch, new_watch);
|
| 1548 |
+
}
|
| 1549 |
+
|
| 1550 |
+
if (ret == ZOK) {
|
| 1551 |
+
XSRETURN_YES;
|
| 1552 |
+
}
|
| 1553 |
+
else {
|
| 1554 |
+
XSRETURN_NO;
|
| 1555 |
+
}
|
| 1556 |
+
|
| 1557 |
+
|
| 1558 |
+
void
|
| 1559 |
+
zk_get_children(zkh, path, ...)
|
| 1560 |
+
Net::ZooKeeper zkh
|
| 1561 |
+
char *path
|
| 1562 |
+
PREINIT:
|
| 1563 |
+
zk_t *zk;
|
| 1564 |
+
zk_watch_t *old_watch = NULL;
|
| 1565 |
+
zk_handle_t *watch_handle = NULL;
|
| 1566 |
+
watcher_fn watcher = NULL;
|
| 1567 |
+
zk_watch_t *new_watch = NULL;
|
| 1568 |
+
struct String_vector strings;
|
| 1569 |
+
int i, ret;
|
| 1570 |
+
PPCODE:
|
| 1571 |
+
zk = _zk_get_handle_outer(aTHX_ zkh);
|
| 1572 |
+
|
| 1573 |
+
if (!zk) {
|
| 1574 |
+
Perl_croak(aTHX_ "invalid handle");
|
| 1575 |
+
}
|
| 1576 |
+
|
| 1577 |
+
zk->last_ret = ZOK;
|
| 1578 |
+
zk->last_errno = 0;
|
| 1579 |
+
|
| 1580 |
+
if (items > 2 && items % 2) {
|
| 1581 |
+
Perl_croak(aTHX_ "invalid number of arguments");
|
| 1582 |
+
}
|
| 1583 |
+
|
| 1584 |
+
for (i = 2; i < items; i += 2) {
|
| 1585 |
+
char *key = SvPV_nolen(ST(i));
|
| 1586 |
+
|
| 1587 |
+
if (strcaseEQ(key, "watch")) {
|
| 1588 |
+
if (!SvROK(ST(i + 1)) || SvTYPE(SvRV(ST(i + 1))) != SVt_PVHV ||
|
| 1589 |
+
!sv_derived_from(ST(i + 1), WATCH_PACKAGE_NAME)) {
|
| 1590 |
+
Perl_croak(aTHX_ "watch is not a hash reference of "
|
| 1591 |
+
"type " WATCH_PACKAGE_NAME);
|
| 1592 |
+
}
|
| 1593 |
+
|
| 1594 |
+
old_watch = _zkw_get_handle_outer(aTHX_ (HV*) SvRV(ST(i + 1)),
|
| 1595 |
+
&watch_handle);
|
| 1596 |
+
|
| 1597 |
+
if (!old_watch) {
|
| 1598 |
+
Perl_croak(aTHX_ "invalid watch handle");
|
| 1599 |
+
}
|
| 1600 |
+
}
|
| 1601 |
+
}
|
| 1602 |
+
|
| 1603 |
+
if (watch_handle) {
|
| 1604 |
+
new_watch = _zk_acquire_watch(aTHX);
|
| 1605 |
+
|
| 1606 |
+
if (!new_watch) {
|
| 1607 |
+
/* errno will be set */
|
| 1608 |
+
zk->last_ret = ZSYSTEMERROR;
|
| 1609 |
+
zk->last_errno = errno;
|
| 1610 |
+
|
| 1611 |
+
if (GIMME_V == G_ARRAY) {
|
| 1612 |
+
XSRETURN_EMPTY;
|
| 1613 |
+
}
|
| 1614 |
+
else {
|
| 1615 |
+
XSRETURN_UNDEF;
|
| 1616 |
+
}
|
| 1617 |
+
}
|
| 1618 |
+
|
| 1619 |
+
watcher = _zk_watcher;
|
| 1620 |
+
}
|
| 1621 |
+
|
| 1622 |
+
Zero(&strings, 1, struct String_vector);
|
| 1623 |
+
|
| 1624 |
+
errno = 0;
|
| 1625 |
+
ret = zoo_wget_children(zk->handle, path, watcher, new_watch,
|
| 1626 |
+
&strings);
|
| 1627 |
+
|
| 1628 |
+
zk->last_ret = ret;
|
| 1629 |
+
zk->last_errno = errno;
|
| 1630 |
+
|
| 1631 |
+
if (watch_handle) {
|
| 1632 |
+
_zk_replace_watch(aTHX_ watch_handle, zk->first_watch,
|
| 1633 |
+
old_watch, new_watch);
|
| 1634 |
+
}
|
| 1635 |
+
|
| 1636 |
+
if (ret == ZOK) {
|
| 1637 |
+
int num_children;
|
| 1638 |
+
|
| 1639 |
+
num_children =
|
| 1640 |
+
(strings.count > PERL_INT_MAX) ? PERL_INT_MAX : strings.count;
|
| 1641 |
+
|
| 1642 |
+
if (GIMME_V == G_ARRAY && num_children > 0) {
|
| 1643 |
+
EXTEND(SP, num_children);
|
| 1644 |
+
|
| 1645 |
+
for (i = 0; i < num_children; ++i) {
|
| 1646 |
+
ST(i) = sv_2mortal(newSVpv(strings.data[i], 0));
|
| 1647 |
+
}
|
| 1648 |
+
}
|
| 1649 |
+
|
| 1650 |
+
/* NOTE: would be nice if this were documented as required */
|
| 1651 |
+
deallocate_String_vector(&strings);
|
| 1652 |
+
|
| 1653 |
+
if (GIMME_V == G_ARRAY) {
|
| 1654 |
+
if (num_children == 0) {
|
| 1655 |
+
XSRETURN_EMPTY;
|
| 1656 |
+
}
|
| 1657 |
+
|
| 1658 |
+
XSRETURN(num_children);
|
| 1659 |
+
}
|
| 1660 |
+
else {
|
| 1661 |
+
ST(0) = sv_2mortal(newSViv(num_children));
|
| 1662 |
+
|
| 1663 |
+
XSRETURN(1);
|
| 1664 |
+
}
|
| 1665 |
+
}
|
| 1666 |
+
else {
|
| 1667 |
+
if (GIMME_V == G_ARRAY) {
|
| 1668 |
+
XSRETURN_EMPTY;
|
| 1669 |
+
}
|
| 1670 |
+
else {
|
| 1671 |
+
XSRETURN_UNDEF;
|
| 1672 |
+
}
|
| 1673 |
+
}
|
| 1674 |
+
|
| 1675 |
+
|
| 1676 |
+
void
|
| 1677 |
+
zk_get(zkh, path, ...)
|
| 1678 |
+
Net::ZooKeeper zkh
|
| 1679 |
+
char *path
|
| 1680 |
+
PREINIT:
|
| 1681 |
+
zk_t *zk;
|
| 1682 |
+
int buf_len;
|
| 1683 |
+
zk_stat_t *stat = NULL;
|
| 1684 |
+
zk_watch_t *old_watch = NULL;
|
| 1685 |
+
zk_handle_t *watch_handle = NULL;
|
| 1686 |
+
char *buf;
|
| 1687 |
+
watcher_fn watcher = NULL;
|
| 1688 |
+
zk_watch_t *new_watch = NULL;
|
| 1689 |
+
int i, ret;
|
| 1690 |
+
PPCODE:
|
| 1691 |
+
zk = _zk_get_handle_outer(aTHX_ zkh);
|
| 1692 |
+
|
| 1693 |
+
if (!zk) {
|
| 1694 |
+
Perl_croak(aTHX_ "invalid handle");
|
| 1695 |
+
}
|
| 1696 |
+
|
| 1697 |
+
zk->last_ret = ZOK;
|
| 1698 |
+
zk->last_errno = 0;
|
| 1699 |
+
|
| 1700 |
+
if (items > 2 && items % 2) {
|
| 1701 |
+
Perl_croak(aTHX_ "invalid number of arguments");
|
| 1702 |
+
}
|
| 1703 |
+
|
| 1704 |
+
buf_len = zk->data_buf_len;
|
| 1705 |
+
|
| 1706 |
+
for (i = 2; i < items; i += 2) {
|
| 1707 |
+
char *key = SvPV_nolen(ST(i));
|
| 1708 |
+
|
| 1709 |
+
if (strcaseEQ(key, "data_read_len")) {
|
| 1710 |
+
buf_len = SvIV(ST(i + 1));
|
| 1711 |
+
|
| 1712 |
+
if (buf_len < 0) {
|
| 1713 |
+
Perl_croak(aTHX_ "invalid data read length: %d",
|
| 1714 |
+
buf_len);
|
| 1715 |
+
}
|
| 1716 |
+
}
|
| 1717 |
+
else if (strcaseEQ(key, "stat")) {
|
| 1718 |
+
if (!SvROK(ST(i + 1)) || SvTYPE(SvRV(ST(i + 1))) != SVt_PVHV ||
|
| 1719 |
+
!sv_derived_from(ST(i + 1), STAT_PACKAGE_NAME)) {
|
| 1720 |
+
Perl_croak(aTHX_ "stat is not a hash reference of "
|
| 1721 |
+
"type " STAT_PACKAGE_NAME);
|
| 1722 |
+
}
|
| 1723 |
+
|
| 1724 |
+
stat = _zks_get_handle_outer(aTHX_ (HV*) SvRV(ST(i + 1)));
|
| 1725 |
+
|
| 1726 |
+
if (!stat) {
|
| 1727 |
+
Perl_croak(aTHX_ "invalid stat handle");
|
| 1728 |
+
}
|
| 1729 |
+
}
|
| 1730 |
+
else if (strcaseEQ(key, "watch")) {
|
| 1731 |
+
if (!SvROK(ST(i + 1)) || SvTYPE(SvRV(ST(i + 1))) != SVt_PVHV ||
|
| 1732 |
+
!sv_derived_from(ST(i + 1), WATCH_PACKAGE_NAME)) {
|
| 1733 |
+
Perl_croak(aTHX_ "watch is not a hash reference of "
|
| 1734 |
+
"type " WATCH_PACKAGE_NAME);
|
| 1735 |
+
}
|
| 1736 |
+
|
| 1737 |
+
old_watch = _zkw_get_handle_outer(aTHX_ (HV*) SvRV(ST(i + 1)),
|
| 1738 |
+
&watch_handle);
|
| 1739 |
+
|
| 1740 |
+
if (!old_watch) {
|
| 1741 |
+
Perl_croak(aTHX_ "invalid watch handle");
|
| 1742 |
+
}
|
| 1743 |
+
}
|
| 1744 |
+
}
|
| 1745 |
+
|
| 1746 |
+
if (watch_handle) {
|
| 1747 |
+
new_watch = _zk_acquire_watch(aTHX);
|
| 1748 |
+
|
| 1749 |
+
if (!new_watch) {
|
| 1750 |
+
/* errno will be set */
|
| 1751 |
+
zk->last_ret = ZSYSTEMERROR;
|
| 1752 |
+
zk->last_errno = errno;
|
| 1753 |
+
|
| 1754 |
+
XSRETURN_UNDEF;
|
| 1755 |
+
}
|
| 1756 |
+
|
| 1757 |
+
watcher = _zk_watcher;
|
| 1758 |
+
}
|
| 1759 |
+
|
| 1760 |
+
Newx(buf, buf_len + 1, char);
|
| 1761 |
+
|
| 1762 |
+
errno = 0;
|
| 1763 |
+
ret = zoo_wget(zk->handle, path, watcher, new_watch,
|
| 1764 |
+
buf, &buf_len, stat);
|
| 1765 |
+
|
| 1766 |
+
zk->last_ret = ret;
|
| 1767 |
+
zk->last_errno = errno;
|
| 1768 |
+
|
| 1769 |
+
if (watch_handle) {
|
| 1770 |
+
_zk_replace_watch(aTHX_ watch_handle, zk->first_watch,
|
| 1771 |
+
old_watch, new_watch);
|
| 1772 |
+
}
|
| 1773 |
+
|
| 1774 |
+
if (ret == ZOK && buf_len != -1) {
|
| 1775 |
+
ST(0) = sv_newmortal();
|
| 1776 |
+
#ifdef SV_HAS_TRAILING_NUL
|
| 1777 |
+
buf[buf_len] = '\0';
|
| 1778 |
+
sv_usepvn_flags(ST(0), buf, buf_len, SV_HAS_TRAILING_NUL);
|
| 1779 |
+
#else
|
| 1780 |
+
sv_usepvn(ST(0), buf, buf_len);
|
| 1781 |
+
#endif
|
| 1782 |
+
|
| 1783 |
+
XSRETURN(1);
|
| 1784 |
+
}
|
| 1785 |
+
else {
|
| 1786 |
+
Safefree(buf);
|
| 1787 |
+
|
| 1788 |
+
XSRETURN_UNDEF;
|
| 1789 |
+
}
|
| 1790 |
+
|
| 1791 |
+
|
| 1792 |
+
void
|
| 1793 |
+
zk_set(zkh, path, buf, ...)
|
| 1794 |
+
Net::ZooKeeper zkh
|
| 1795 |
+
char *path
|
| 1796 |
+
char *buf; buf = (char *) SvPV($arg, buf_len);
|
| 1797 |
+
PREINIT:
|
| 1798 |
+
zk_t *zk;
|
| 1799 |
+
int version = -1;
|
| 1800 |
+
zk_stat_t *stat = NULL;
|
| 1801 |
+
STRLEN buf_len;
|
| 1802 |
+
int i, ret;
|
| 1803 |
+
PPCODE:
|
| 1804 |
+
zk = _zk_get_handle_outer(aTHX_ zkh);
|
| 1805 |
+
|
| 1806 |
+
if (!zk) {
|
| 1807 |
+
Perl_croak(aTHX_ "invalid handle");
|
| 1808 |
+
}
|
| 1809 |
+
|
| 1810 |
+
zk->last_ret = ZOK;
|
| 1811 |
+
zk->last_errno = 0;
|
| 1812 |
+
|
| 1813 |
+
if (items > 3 && !(items % 2)) {
|
| 1814 |
+
Perl_croak(aTHX_ "invalid number of arguments");
|
| 1815 |
+
}
|
| 1816 |
+
|
| 1817 |
+
if (buf_len > PERL_INT_MAX) {
|
| 1818 |
+
Perl_croak(aTHX_ "invalid data length: %zu", buf_len);
|
| 1819 |
+
}
|
| 1820 |
+
|
| 1821 |
+
for (i = 3; i < items; i += 2) {
|
| 1822 |
+
char *key = SvPV_nolen(ST(i));
|
| 1823 |
+
|
| 1824 |
+
if (strcaseEQ(key, "version")) {
|
| 1825 |
+
version = SvIV(ST(i + 1));
|
| 1826 |
+
|
| 1827 |
+
if (version < 0) {
|
| 1828 |
+
Perl_croak(aTHX_ "invalid version requirement: %d",
|
| 1829 |
+
version);
|
| 1830 |
+
}
|
| 1831 |
+
}
|
| 1832 |
+
else if (strcaseEQ(key, "stat")) {
|
| 1833 |
+
if (!SvROK(ST(i + 1)) || SvTYPE(SvRV(ST(i + 1))) != SVt_PVHV ||
|
| 1834 |
+
!sv_derived_from(ST(i + 1), STAT_PACKAGE_NAME)) {
|
| 1835 |
+
Perl_croak(aTHX_ "stat is not a hash reference of "
|
| 1836 |
+
"type " STAT_PACKAGE_NAME);
|
| 1837 |
+
}
|
| 1838 |
+
|
| 1839 |
+
stat = _zks_get_handle_outer(aTHX_ (HV*) SvRV(ST(i + 1)));
|
| 1840 |
+
|
| 1841 |
+
if (!stat) {
|
| 1842 |
+
Perl_croak(aTHX_ "invalid stat handle");
|
| 1843 |
+
}
|
| 1844 |
+
}
|
| 1845 |
+
}
|
| 1846 |
+
|
| 1847 |
+
errno = 0;
|
| 1848 |
+
ret = zoo_set2(zk->handle, path, buf, buf_len, version, stat);
|
| 1849 |
+
|
| 1850 |
+
zk->last_ret = ret;
|
| 1851 |
+
zk->last_errno = errno;
|
| 1852 |
+
|
| 1853 |
+
if (ret == ZOK) {
|
| 1854 |
+
XSRETURN_YES;
|
| 1855 |
+
}
|
| 1856 |
+
else {
|
| 1857 |
+
XSRETURN_NO;
|
| 1858 |
+
}
|
| 1859 |
+
|
| 1860 |
+
|
| 1861 |
+
void
|
| 1862 |
+
zk_get_acl(zkh, path, ...)
|
| 1863 |
+
Net::ZooKeeper zkh
|
| 1864 |
+
char *path
|
| 1865 |
+
PREINIT:
|
| 1866 |
+
zk_t *zk;
|
| 1867 |
+
zk_stat_t *stat = NULL;
|
| 1868 |
+
struct ACL_vector acl;
|
| 1869 |
+
int i, ret;
|
| 1870 |
+
PPCODE:
|
| 1871 |
+
zk = _zk_get_handle_outer(aTHX_ zkh);
|
| 1872 |
+
|
| 1873 |
+
if (!zk) {
|
| 1874 |
+
Perl_croak(aTHX_ "invalid handle");
|
| 1875 |
+
}
|
| 1876 |
+
|
| 1877 |
+
zk->last_ret = ZOK;
|
| 1878 |
+
zk->last_errno = 0;
|
| 1879 |
+
|
| 1880 |
+
if (items > 2 && items % 2) {
|
| 1881 |
+
Perl_croak(aTHX_ "invalid number of arguments");
|
| 1882 |
+
}
|
| 1883 |
+
|
| 1884 |
+
for (i = 2; i < items; i += 2) {
|
| 1885 |
+
char *key = SvPV_nolen(ST(i));
|
| 1886 |
+
|
| 1887 |
+
if (strcaseEQ(key, "stat")) {
|
| 1888 |
+
if (!SvROK(ST(i + 1)) || SvTYPE(SvRV(ST(i + 1))) != SVt_PVHV ||
|
| 1889 |
+
!sv_derived_from(ST(i + 1), STAT_PACKAGE_NAME)) {
|
| 1890 |
+
Perl_croak(aTHX_ "stat is not a hash reference of "
|
| 1891 |
+
"type " STAT_PACKAGE_NAME);
|
| 1892 |
+
}
|
| 1893 |
+
|
| 1894 |
+
stat = _zks_get_handle_outer(aTHX_ (HV*) SvRV(ST(i + 1)));
|
| 1895 |
+
|
| 1896 |
+
if (!stat) {
|
| 1897 |
+
Perl_croak(aTHX_ "invalid stat handle");
|
| 1898 |
+
}
|
| 1899 |
+
}
|
| 1900 |
+
}
|
| 1901 |
+
|
| 1902 |
+
errno = 0;
|
| 1903 |
+
ret = zoo_get_acl(zk->handle, path, &acl, stat);
|
| 1904 |
+
|
| 1905 |
+
zk->last_ret = ret;
|
| 1906 |
+
zk->last_errno = errno;
|
| 1907 |
+
|
| 1908 |
+
if (ret == ZOK) {
|
| 1909 |
+
int num_acl_entries;
|
| 1910 |
+
|
| 1911 |
+
num_acl_entries =
|
| 1912 |
+
(acl.count > PERL_INT_MAX) ? PERL_INT_MAX : acl.count;
|
| 1913 |
+
|
| 1914 |
+
if (GIMME_V == G_ARRAY && num_acl_entries > 0) {
|
| 1915 |
+
EXTEND(SP, num_acl_entries);
|
| 1916 |
+
|
| 1917 |
+
for (i = 0; i < num_acl_entries; ++i) {
|
| 1918 |
+
HV *acl_entry_hash = newHV();
|
| 1919 |
+
|
| 1920 |
+
_zk_fill_acl_entry_hash(aTHX_ &acl.data[i],
|
| 1921 |
+
acl_entry_hash);
|
| 1922 |
+
|
| 1923 |
+
ST(i) = sv_2mortal(newRV_noinc((SV*) acl_entry_hash));
|
| 1924 |
+
}
|
| 1925 |
+
}
|
| 1926 |
+
|
| 1927 |
+
/* NOTE: would be nice if this were documented as required */
|
| 1928 |
+
deallocate_ACL_vector(&acl);
|
| 1929 |
+
|
| 1930 |
+
if (GIMME_V == G_ARRAY) {
|
| 1931 |
+
if (num_acl_entries == 0) {
|
| 1932 |
+
XSRETURN_EMPTY;
|
| 1933 |
+
}
|
| 1934 |
+
|
| 1935 |
+
XSRETURN(num_acl_entries);
|
| 1936 |
+
}
|
| 1937 |
+
else {
|
| 1938 |
+
ST(0) = sv_2mortal(newSViv(num_acl_entries));
|
| 1939 |
+
|
| 1940 |
+
XSRETURN(1);
|
| 1941 |
+
}
|
| 1942 |
+
}
|
| 1943 |
+
else {
|
| 1944 |
+
if (GIMME_V == G_ARRAY) {
|
| 1945 |
+
XSRETURN_EMPTY;
|
| 1946 |
+
}
|
| 1947 |
+
else {
|
| 1948 |
+
XSRETURN_UNDEF;
|
| 1949 |
+
}
|
| 1950 |
+
}
|
| 1951 |
+
|
| 1952 |
+
|
| 1953 |
+
void
|
| 1954 |
+
zk_set_acl(zkh, path, acl_arr, ...)
|
| 1955 |
+
Net::ZooKeeper zkh
|
| 1956 |
+
char *path
|
| 1957 |
+
AV *acl_arr
|
| 1958 |
+
PREINIT:
|
| 1959 |
+
zk_t *zk;
|
| 1960 |
+
const char *err;
|
| 1961 |
+
int version = -1;
|
| 1962 |
+
struct ACL_vector acl;
|
| 1963 |
+
int i, ret;
|
| 1964 |
+
PPCODE:
|
| 1965 |
+
zk = _zk_get_handle_outer(aTHX_ zkh);
|
| 1966 |
+
|
| 1967 |
+
if (!zk) {
|
| 1968 |
+
Perl_croak(aTHX_ "invalid handle");
|
| 1969 |
+
}
|
| 1970 |
+
|
| 1971 |
+
zk->last_ret = ZOK;
|
| 1972 |
+
zk->last_errno = 0;
|
| 1973 |
+
|
| 1974 |
+
if (items > 3 && !(items % 2)) {
|
| 1975 |
+
Perl_croak(aTHX_ "invalid number of arguments");
|
| 1976 |
+
}
|
| 1977 |
+
|
| 1978 |
+
err = _zk_fill_acl(aTHX_ acl_arr, &acl);
|
| 1979 |
+
|
| 1980 |
+
if (err) {
|
| 1981 |
+
Perl_croak(aTHX_ "%s", err);
|
| 1982 |
+
}
|
| 1983 |
+
|
| 1984 |
+
for (i = 3; i < items; i += 2) {
|
| 1985 |
+
char *key = SvPV_nolen(ST(i));
|
| 1986 |
+
|
| 1987 |
+
if (strcaseEQ(key, "version")) {
|
| 1988 |
+
version = SvIV(ST(i + 1));
|
| 1989 |
+
|
| 1990 |
+
if (version < 0) {
|
| 1991 |
+
Perl_croak(aTHX_ "invalid version requirement: %d",
|
| 1992 |
+
version);
|
| 1993 |
+
}
|
| 1994 |
+
}
|
| 1995 |
+
}
|
| 1996 |
+
|
| 1997 |
+
errno = 0;
|
| 1998 |
+
ret = zoo_set_acl(zk->handle, path, version, &acl);
|
| 1999 |
+
|
| 2000 |
+
zk->last_ret = ret;
|
| 2001 |
+
zk->last_errno = errno;
|
| 2002 |
+
|
| 2003 |
+
_zk_free_acl(aTHX_ &acl);
|
| 2004 |
+
|
| 2005 |
+
if (ret == ZOK) {
|
| 2006 |
+
XSRETURN_YES;
|
| 2007 |
+
}
|
| 2008 |
+
else {
|
| 2009 |
+
XSRETURN_NO;
|
| 2010 |
+
}
|
| 2011 |
+
|
| 2012 |
+
|
| 2013 |
+
void
|
| 2014 |
+
zk_stat(zkh)
|
| 2015 |
+
Net::ZooKeeper zkh
|
| 2016 |
+
PREINIT:
|
| 2017 |
+
zk_t *zk;
|
| 2018 |
+
zk_handle_t *handle;
|
| 2019 |
+
HV *stash, *stat_hash, *attr_hash;
|
| 2020 |
+
SV *attr;
|
| 2021 |
+
PPCODE:
|
| 2022 |
+
zk = _zk_get_handle_outer(aTHX_ zkh);
|
| 2023 |
+
|
| 2024 |
+
if (!zk) {
|
| 2025 |
+
Perl_croak(aTHX_ "invalid handle");
|
| 2026 |
+
}
|
| 2027 |
+
|
| 2028 |
+
zk->last_ret = ZOK;
|
| 2029 |
+
zk->last_errno = 0;
|
| 2030 |
+
|
| 2031 |
+
Newx(handle, 1, zk_handle_t);
|
| 2032 |
+
|
| 2033 |
+
handle->signature = STAT_PACKAGE_SIGNATURE;
|
| 2034 |
+
|
| 2035 |
+
Newxz(handle->handle.stat, 1, zk_stat_t);
|
| 2036 |
+
|
| 2037 |
+
/* As in zk_new(), we use two levels of magic here. */
|
| 2038 |
+
|
| 2039 |
+
stash = gv_stashpv(STAT_PACKAGE_NAME, GV_ADDWARN);
|
| 2040 |
+
|
| 2041 |
+
attr_hash = newHV();
|
| 2042 |
+
|
| 2043 |
+
sv_magic((SV*) attr_hash, Nullsv, PERL_MAGIC_ext,
|
| 2044 |
+
(const char*) handle, 0);
|
| 2045 |
+
|
| 2046 |
+
attr = sv_bless(newRV_noinc((SV*) attr_hash), stash);
|
| 2047 |
+
|
| 2048 |
+
stat_hash = newHV();
|
| 2049 |
+
|
| 2050 |
+
sv_magic((SV*) stat_hash, attr, PERL_MAGIC_tied, Nullch, 0);
|
| 2051 |
+
SvREFCNT_dec(attr);
|
| 2052 |
+
|
| 2053 |
+
ST(0) = sv_bless(sv_2mortal(newRV_noinc((SV*) stat_hash)), stash);
|
| 2054 |
+
|
| 2055 |
+
XSRETURN(1);
|
| 2056 |
+
|
| 2057 |
+
|
| 2058 |
+
void
|
| 2059 |
+
zk_watch(zkh, ...)
|
| 2060 |
+
Net::ZooKeeper zkh
|
| 2061 |
+
PREINIT:
|
| 2062 |
+
zk_t *zk;
|
| 2063 |
+
unsigned int timeout;
|
| 2064 |
+
zk_watch_t *watch;
|
| 2065 |
+
zk_handle_t *handle;
|
| 2066 |
+
HV *stash, *watch_hash, *attr_hash;
|
| 2067 |
+
SV *attr;
|
| 2068 |
+
int i;
|
| 2069 |
+
PPCODE:
|
| 2070 |
+
zk = _zk_get_handle_outer(aTHX_ zkh);
|
| 2071 |
+
|
| 2072 |
+
if (!zk) {
|
| 2073 |
+
Perl_croak(aTHX_ "invalid handle");
|
| 2074 |
+
}
|
| 2075 |
+
|
| 2076 |
+
zk->last_ret = ZOK;
|
| 2077 |
+
zk->last_errno = 0;
|
| 2078 |
+
|
| 2079 |
+
if (items > 1 && !(items % 2)) {
|
| 2080 |
+
Perl_croak(aTHX_ "invalid number of arguments");
|
| 2081 |
+
}
|
| 2082 |
+
|
| 2083 |
+
timeout = zk->watch_timeout;
|
| 2084 |
+
|
| 2085 |
+
for (i = 1; i < items; i += 2) {
|
| 2086 |
+
char *key = SvPV_nolen(ST(i));
|
| 2087 |
+
|
| 2088 |
+
if (strcaseEQ(key, "timeout")) {
|
| 2089 |
+
timeout = SvUV(ST(i + 1));
|
| 2090 |
+
}
|
| 2091 |
+
}
|
| 2092 |
+
|
| 2093 |
+
watch = _zk_acquire_watch(aTHX);
|
| 2094 |
+
|
| 2095 |
+
if (!watch) {
|
| 2096 |
+
/* errno will be set */
|
| 2097 |
+
zk->last_ret = ZSYSTEMERROR;
|
| 2098 |
+
zk->last_errno = errno;
|
| 2099 |
+
|
| 2100 |
+
XSRETURN_UNDEF;
|
| 2101 |
+
}
|
| 2102 |
+
|
| 2103 |
+
Newx(handle, 1, zk_handle_t);
|
| 2104 |
+
|
| 2105 |
+
handle->signature = WATCH_PACKAGE_SIGNATURE;
|
| 2106 |
+
handle->handle.watch = watch;
|
| 2107 |
+
|
| 2108 |
+
/* As in zk_new(), we use two levels of magic here. */
|
| 2109 |
+
|
| 2110 |
+
stash = gv_stashpv(WATCH_PACKAGE_NAME, GV_ADDWARN);
|
| 2111 |
+
|
| 2112 |
+
attr_hash = newHV();
|
| 2113 |
+
|
| 2114 |
+
watch->timeout = timeout;
|
| 2115 |
+
|
| 2116 |
+
sv_magic((SV*) attr_hash, Nullsv, PERL_MAGIC_ext,
|
| 2117 |
+
(const char*) handle, 0);
|
| 2118 |
+
|
| 2119 |
+
attr = sv_bless(newRV_noinc((SV*) attr_hash), stash);
|
| 2120 |
+
|
| 2121 |
+
watch_hash = newHV();
|
| 2122 |
+
|
| 2123 |
+
sv_magic((SV*) watch_hash, attr, PERL_MAGIC_tied, Nullch, 0);
|
| 2124 |
+
SvREFCNT_dec(attr);
|
| 2125 |
+
|
| 2126 |
+
ST(0) = sv_bless(sv_2mortal(newRV_noinc((SV*) watch_hash)), stash);
|
| 2127 |
+
|
| 2128 |
+
XSRETURN(1);
|
| 2129 |
+
|
| 2130 |
+
|
| 2131 |
+
MODULE = Net::ZooKeeper PACKAGE = Net::ZooKeeper::Stat PREFIX = zks_
|
| 2132 |
+
|
| 2133 |
+
void
|
| 2134 |
+
zks_DESTROY(zksh)
|
| 2135 |
+
Net::ZooKeeper::Stat zksh
|
| 2136 |
+
PREINIT:
|
| 2137 |
+
zk_handle_t *handle;
|
| 2138 |
+
HV *attr_hash;
|
| 2139 |
+
int ret = ZBADARGUMENTS;
|
| 2140 |
+
PPCODE:
|
| 2141 |
+
handle = _zk_check_handle_outer(aTHX_ zksh, &attr_hash,
|
| 2142 |
+
STAT_PACKAGE_NAME,
|
| 2143 |
+
STAT_PACKAGE_SIGNATURE);
|
| 2144 |
+
|
| 2145 |
+
if (!handle) {
|
| 2146 |
+
handle = _zk_check_handle_inner(aTHX_ zksh,
|
| 2147 |
+
STAT_PACKAGE_SIGNATURE);
|
| 2148 |
+
|
| 2149 |
+
if (handle) {
|
| 2150 |
+
attr_hash = zksh;
|
| 2151 |
+
zksh = NULL;
|
| 2152 |
+
}
|
| 2153 |
+
}
|
| 2154 |
+
|
| 2155 |
+
if (handle) {
|
| 2156 |
+
ret = ZOK;
|
| 2157 |
+
|
| 2158 |
+
Safefree(handle->handle.stat);
|
| 2159 |
+
Safefree(handle);
|
| 2160 |
+
|
| 2161 |
+
sv_unmagic((SV*) attr_hash, PERL_MAGIC_ext);
|
| 2162 |
+
}
|
| 2163 |
+
|
| 2164 |
+
if (zksh && attr_hash) {
|
| 2165 |
+
sv_unmagic((SV*) zksh, PERL_MAGIC_tied);
|
| 2166 |
+
}
|
| 2167 |
+
|
| 2168 |
+
if (GIMME_V == G_VOID) {
|
| 2169 |
+
XSRETURN_EMPTY;
|
| 2170 |
+
}
|
| 2171 |
+
else if (ret == ZOK) {
|
| 2172 |
+
XSRETURN_YES;
|
| 2173 |
+
}
|
| 2174 |
+
else {
|
| 2175 |
+
XSRETURN_NO;
|
| 2176 |
+
}
|
| 2177 |
+
|
| 2178 |
+
|
| 2179 |
+
void
|
| 2180 |
+
zks_CLONE(package)
|
| 2181 |
+
char *package
|
| 2182 |
+
PPCODE:
|
| 2183 |
+
XSRETURN_EMPTY;
|
| 2184 |
+
|
| 2185 |
+
|
| 2186 |
+
void
|
| 2187 |
+
zks_CLONE_SKIP(package)
|
| 2188 |
+
char *package
|
| 2189 |
+
PPCODE:
|
| 2190 |
+
XSRETURN_YES;
|
| 2191 |
+
|
| 2192 |
+
|
| 2193 |
+
void
|
| 2194 |
+
zks_TIEHASH(package, ...)
|
| 2195 |
+
char *package
|
| 2196 |
+
PPCODE:
|
| 2197 |
+
Perl_croak(aTHX_ "tying hashes of class "
|
| 2198 |
+
STAT_PACKAGE_NAME " not supported");
|
| 2199 |
+
|
| 2200 |
+
|
| 2201 |
+
void
|
| 2202 |
+
zks_UNTIE(attr_hash, ref_count)
|
| 2203 |
+
Net::ZooKeeper::Stat attr_hash
|
| 2204 |
+
IV ref_count
|
| 2205 |
+
PPCODE:
|
| 2206 |
+
Perl_croak(aTHX_ "untying hashes of class "
|
| 2207 |
+
STAT_PACKAGE_NAME " not supported");
|
| 2208 |
+
|
| 2209 |
+
|
| 2210 |
+
void
|
| 2211 |
+
zks_FIRSTKEY(attr_hash)
|
| 2212 |
+
Net::ZooKeeper::Stat attr_hash
|
| 2213 |
+
PREINIT:
|
| 2214 |
+
zk_stat_t *stat;
|
| 2215 |
+
PPCODE:
|
| 2216 |
+
stat = _zks_get_handle_inner(aTHX_ attr_hash);
|
| 2217 |
+
|
| 2218 |
+
if (!stat) {
|
| 2219 |
+
Perl_croak(aTHX_ "invalid handle");
|
| 2220 |
+
}
|
| 2221 |
+
|
| 2222 |
+
ST(0) = sv_2mortal(newSVpvn(zk_stat_keys[0].name,
|
| 2223 |
+
zk_stat_keys[0].name_len));
|
| 2224 |
+
|
| 2225 |
+
XSRETURN(1);
|
| 2226 |
+
|
| 2227 |
+
|
| 2228 |
+
void
|
| 2229 |
+
zks_NEXTKEY(attr_hash, attr_key)
|
| 2230 |
+
Net::ZooKeeper::Stat attr_hash
|
| 2231 |
+
SV *attr_key
|
| 2232 |
+
PREINIT:
|
| 2233 |
+
zk_stat_t *stat;
|
| 2234 |
+
char *key;
|
| 2235 |
+
int i;
|
| 2236 |
+
PPCODE:
|
| 2237 |
+
stat = _zks_get_handle_inner(aTHX_ attr_hash);
|
| 2238 |
+
|
| 2239 |
+
if (!stat) {
|
| 2240 |
+
Perl_croak(aTHX_ "invalid handle");
|
| 2241 |
+
}
|
| 2242 |
+
|
| 2243 |
+
key = SvPV_nolen(attr_key);
|
| 2244 |
+
|
| 2245 |
+
for (i = 0; i < NUM_STAT_KEYS; ++i) {
|
| 2246 |
+
if (strcaseEQ(key, zk_stat_keys[i].name)) {
|
| 2247 |
+
++i;
|
| 2248 |
+
|
| 2249 |
+
break;
|
| 2250 |
+
}
|
| 2251 |
+
}
|
| 2252 |
+
|
| 2253 |
+
if (i < NUM_STAT_KEYS) {
|
| 2254 |
+
ST(0) = sv_2mortal(newSVpvn(zk_stat_keys[i].name,
|
| 2255 |
+
zk_stat_keys[i].name_len));
|
| 2256 |
+
|
| 2257 |
+
XSRETURN(1);
|
| 2258 |
+
}
|
| 2259 |
+
else {
|
| 2260 |
+
XSRETURN_EMPTY;
|
| 2261 |
+
}
|
| 2262 |
+
|
| 2263 |
+
|
| 2264 |
+
void
|
| 2265 |
+
zks_SCALAR(attr_hash)
|
| 2266 |
+
Net::ZooKeeper::Stat attr_hash
|
| 2267 |
+
PPCODE:
|
| 2268 |
+
XSRETURN_YES;
|
| 2269 |
+
|
| 2270 |
+
|
| 2271 |
+
void
|
| 2272 |
+
zks_FETCH(attr_hash, attr_key)
|
| 2273 |
+
Net::ZooKeeper::Stat attr_hash
|
| 2274 |
+
SV *attr_key
|
| 2275 |
+
PREINIT:
|
| 2276 |
+
zk_stat_t *stat;
|
| 2277 |
+
char *key;
|
| 2278 |
+
SV *val = NULL;
|
| 2279 |
+
int i;
|
| 2280 |
+
PPCODE:
|
| 2281 |
+
stat = _zks_get_handle_inner(aTHX_ attr_hash);
|
| 2282 |
+
|
| 2283 |
+
if (!stat) {
|
| 2284 |
+
Perl_croak(aTHX_ "invalid handle");
|
| 2285 |
+
}
|
| 2286 |
+
|
| 2287 |
+
key = SvPV_nolen(attr_key);
|
| 2288 |
+
|
| 2289 |
+
for (i = 0; i < NUM_STAT_KEYS; ++i) {
|
| 2290 |
+
if (strcaseEQ(key, zk_stat_keys[i].name)) {
|
| 2291 |
+
if (zk_stat_keys[i].size * CHAR_BIT == 32) {
|
| 2292 |
+
val = newSViv(*((int32_t*) (((char*) stat) +
|
| 2293 |
+
zk_stat_keys[i].offset)));
|
| 2294 |
+
}
|
| 2295 |
+
else {
|
| 2296 |
+
/* NOTE: %lld is inconsistent, so cast to a double */
|
| 2297 |
+
val = newSVpvf("%.0f", (double)
|
| 2298 |
+
*((int64_t*) (((char*) stat) +
|
| 2299 |
+
zk_stat_keys[i].offset)));
|
| 2300 |
+
}
|
| 2301 |
+
|
| 2302 |
+
break;
|
| 2303 |
+
}
|
| 2304 |
+
}
|
| 2305 |
+
|
| 2306 |
+
if (val) {
|
| 2307 |
+
ST(0) = sv_2mortal(val);
|
| 2308 |
+
|
| 2309 |
+
XSRETURN(1);
|
| 2310 |
+
}
|
| 2311 |
+
|
| 2312 |
+
Perl_warn(aTHX_ "invalid element: %s", key);
|
| 2313 |
+
|
| 2314 |
+
XSRETURN_UNDEF;
|
| 2315 |
+
|
| 2316 |
+
|
| 2317 |
+
void
|
| 2318 |
+
zks_STORE(attr_hash, attr_key, attr_val)
|
| 2319 |
+
Net::ZooKeeper::Stat attr_hash
|
| 2320 |
+
SV *attr_key
|
| 2321 |
+
SV *attr_val
|
| 2322 |
+
PREINIT:
|
| 2323 |
+
zk_stat_t *stat;
|
| 2324 |
+
char *key;
|
| 2325 |
+
int i;
|
| 2326 |
+
PPCODE:
|
| 2327 |
+
stat = _zks_get_handle_inner(aTHX_ attr_hash);
|
| 2328 |
+
|
| 2329 |
+
if (!stat) {
|
| 2330 |
+
Perl_croak(aTHX_ "invalid handle");
|
| 2331 |
+
}
|
| 2332 |
+
|
| 2333 |
+
key = SvPV_nolen(attr_key);
|
| 2334 |
+
|
| 2335 |
+
for (i = 0; i < NUM_STAT_KEYS; ++i) {
|
| 2336 |
+
if (strcaseEQ(key, zk_stat_keys[i].name)) {
|
| 2337 |
+
Perl_warn(aTHX_ "read-only element: %s", key);
|
| 2338 |
+
|
| 2339 |
+
XSRETURN_EMPTY;
|
| 2340 |
+
}
|
| 2341 |
+
}
|
| 2342 |
+
|
| 2343 |
+
Perl_warn(aTHX_ "invalid element: %s", key);
|
| 2344 |
+
|
| 2345 |
+
XSRETURN_EMPTY;
|
| 2346 |
+
|
| 2347 |
+
|
| 2348 |
+
void
|
| 2349 |
+
zks_EXISTS(attr_hash, attr_key)
|
| 2350 |
+
Net::ZooKeeper::Stat attr_hash
|
| 2351 |
+
SV *attr_key
|
| 2352 |
+
PREINIT:
|
| 2353 |
+
zk_stat_t *stat;
|
| 2354 |
+
char *key;
|
| 2355 |
+
int i;
|
| 2356 |
+
PPCODE:
|
| 2357 |
+
stat = _zks_get_handle_inner(aTHX_ attr_hash);
|
| 2358 |
+
|
| 2359 |
+
if (!stat) {
|
| 2360 |
+
Perl_croak(aTHX_ "invalid handle");
|
| 2361 |
+
}
|
| 2362 |
+
|
| 2363 |
+
key = SvPV_nolen(attr_key);
|
| 2364 |
+
|
| 2365 |
+
for (i = 0; i < NUM_STAT_KEYS; ++i) {
|
| 2366 |
+
if (strcaseEQ(key, zk_stat_keys[i].name)) {
|
| 2367 |
+
XSRETURN_YES;
|
| 2368 |
+
}
|
| 2369 |
+
}
|
| 2370 |
+
|
| 2371 |
+
XSRETURN_NO;
|
| 2372 |
+
|
| 2373 |
+
|
| 2374 |
+
void
|
| 2375 |
+
zks_DELETE(attr_hash, attr_key)
|
| 2376 |
+
Net::ZooKeeper::Stat attr_hash
|
| 2377 |
+
SV *attr_key
|
| 2378 |
+
PPCODE:
|
| 2379 |
+
Perl_warn(aTHX_ "deleting elements from hashes of class "
|
| 2380 |
+
STAT_PACKAGE_NAME " not supported");
|
| 2381 |
+
|
| 2382 |
+
XSRETURN_EMPTY;
|
| 2383 |
+
|
| 2384 |
+
|
| 2385 |
+
void
|
| 2386 |
+
zks_CLEAR(attr_hash)
|
| 2387 |
+
Net::ZooKeeper::Stat attr_hash
|
| 2388 |
+
PPCODE:
|
| 2389 |
+
Perl_warn(aTHX_ "clearing hashes of class "
|
| 2390 |
+
STAT_PACKAGE_NAME " not supported");
|
| 2391 |
+
|
| 2392 |
+
XSRETURN_EMPTY;
|
| 2393 |
+
|
| 2394 |
+
|
| 2395 |
+
MODULE = Net::ZooKeeper PACKAGE = Net::ZooKeeper::Watch PREFIX = zkw_
|
| 2396 |
+
|
| 2397 |
+
void
|
| 2398 |
+
zkw_DESTROY(zkwh)
|
| 2399 |
+
Net::ZooKeeper::Watch zkwh
|
| 2400 |
+
PREINIT:
|
| 2401 |
+
zk_handle_t *handle;
|
| 2402 |
+
HV *attr_hash;
|
| 2403 |
+
int ret = ZBADARGUMENTS;
|
| 2404 |
+
PPCODE:
|
| 2405 |
+
handle = _zk_check_handle_outer(aTHX_ zkwh, &attr_hash,
|
| 2406 |
+
WATCH_PACKAGE_NAME,
|
| 2407 |
+
WATCH_PACKAGE_SIGNATURE);
|
| 2408 |
+
|
| 2409 |
+
if (!handle) {
|
| 2410 |
+
handle = _zk_check_handle_inner(aTHX_ zkwh,
|
| 2411 |
+
WATCH_PACKAGE_SIGNATURE);
|
| 2412 |
+
|
| 2413 |
+
if (handle) {
|
| 2414 |
+
attr_hash = zkwh;
|
| 2415 |
+
zkwh = NULL;
|
| 2416 |
+
}
|
| 2417 |
+
}
|
| 2418 |
+
|
| 2419 |
+
if (handle) {
|
| 2420 |
+
ret = ZOK;
|
| 2421 |
+
|
| 2422 |
+
_zk_release_watch(aTHX_ handle->handle.watch, 0);
|
| 2423 |
+
Safefree(handle);
|
| 2424 |
+
|
| 2425 |
+
sv_unmagic((SV*) attr_hash, PERL_MAGIC_ext);
|
| 2426 |
+
}
|
| 2427 |
+
|
| 2428 |
+
if (zkwh && attr_hash) {
|
| 2429 |
+
sv_unmagic((SV*) zkwh, PERL_MAGIC_tied);
|
| 2430 |
+
}
|
| 2431 |
+
|
| 2432 |
+
if (GIMME_V == G_VOID) {
|
| 2433 |
+
XSRETURN_EMPTY;
|
| 2434 |
+
}
|
| 2435 |
+
else if (ret == ZOK) {
|
| 2436 |
+
XSRETURN_YES;
|
| 2437 |
+
}
|
| 2438 |
+
else {
|
| 2439 |
+
XSRETURN_NO;
|
| 2440 |
+
}
|
| 2441 |
+
|
| 2442 |
+
|
| 2443 |
+
void
|
| 2444 |
+
zkw_CLONE(package)
|
| 2445 |
+
char *package
|
| 2446 |
+
PPCODE:
|
| 2447 |
+
XSRETURN_EMPTY;
|
| 2448 |
+
|
| 2449 |
+
|
| 2450 |
+
void
|
| 2451 |
+
zkw_CLONE_SKIP(package)
|
| 2452 |
+
char *package
|
| 2453 |
+
PPCODE:
|
| 2454 |
+
XSRETURN_YES;
|
| 2455 |
+
|
| 2456 |
+
|
| 2457 |
+
void
|
| 2458 |
+
zkw_TIEHASH(package, ...)
|
| 2459 |
+
char *package
|
| 2460 |
+
PPCODE:
|
| 2461 |
+
Perl_croak(aTHX_ "tying hashes of class "
|
| 2462 |
+
WATCH_PACKAGE_NAME " not supported");
|
| 2463 |
+
|
| 2464 |
+
|
| 2465 |
+
void
|
| 2466 |
+
zkw_UNTIE(attr_hash, ref_count)
|
| 2467 |
+
Net::ZooKeeper::Watch attr_hash
|
| 2468 |
+
IV ref_count
|
| 2469 |
+
PPCODE:
|
| 2470 |
+
Perl_croak(aTHX_ "untying hashes of class "
|
| 2471 |
+
WATCH_PACKAGE_NAME " not supported");
|
| 2472 |
+
|
| 2473 |
+
|
| 2474 |
+
void
|
| 2475 |
+
zkw_FIRSTKEY(attr_hash)
|
| 2476 |
+
Net::ZooKeeper::Watch attr_hash
|
| 2477 |
+
PREINIT:
|
| 2478 |
+
zk_watch_t *watch;
|
| 2479 |
+
PPCODE:
|
| 2480 |
+
watch = _zkw_get_handle_inner(aTHX_ attr_hash);
|
| 2481 |
+
|
| 2482 |
+
if (!watch) {
|
| 2483 |
+
Perl_croak(aTHX_ "invalid handle");
|
| 2484 |
+
}
|
| 2485 |
+
|
| 2486 |
+
ST(0) = sv_2mortal(newSVpvn(zk_watch_keys[0].name,
|
| 2487 |
+
zk_watch_keys[0].name_len));
|
| 2488 |
+
|
| 2489 |
+
XSRETURN(1);
|
| 2490 |
+
|
| 2491 |
+
|
| 2492 |
+
void
|
| 2493 |
+
zkw_NEXTKEY(attr_hash, attr_key)
|
| 2494 |
+
Net::ZooKeeper::Watch attr_hash
|
| 2495 |
+
SV *attr_key
|
| 2496 |
+
PREINIT:
|
| 2497 |
+
zk_watch_t *watch;
|
| 2498 |
+
char *key;
|
| 2499 |
+
int i;
|
| 2500 |
+
PPCODE:
|
| 2501 |
+
watch = _zkw_get_handle_inner(aTHX_ attr_hash);
|
| 2502 |
+
|
| 2503 |
+
if (!watch) {
|
| 2504 |
+
Perl_croak(aTHX_ "invalid handle");
|
| 2505 |
+
}
|
| 2506 |
+
|
| 2507 |
+
key = SvPV_nolen(attr_key);
|
| 2508 |
+
|
| 2509 |
+
for (i = 0; i < NUM_WATCH_KEYS; ++i) {
|
| 2510 |
+
if (strcaseEQ(key, zk_watch_keys[i].name)) {
|
| 2511 |
+
++i;
|
| 2512 |
+
|
| 2513 |
+
break;
|
| 2514 |
+
}
|
| 2515 |
+
}
|
| 2516 |
+
|
| 2517 |
+
if (i < NUM_WATCH_KEYS) {
|
| 2518 |
+
ST(0) = sv_2mortal(newSVpvn(zk_watch_keys[i].name,
|
| 2519 |
+
zk_watch_keys[i].name_len));
|
| 2520 |
+
|
| 2521 |
+
XSRETURN(1);
|
| 2522 |
+
}
|
| 2523 |
+
else {
|
| 2524 |
+
XSRETURN_EMPTY;
|
| 2525 |
+
}
|
| 2526 |
+
|
| 2527 |
+
|
| 2528 |
+
void
|
| 2529 |
+
zkw_SCALAR(attr_hash)
|
| 2530 |
+
Net::ZooKeeper::Watch attr_hash
|
| 2531 |
+
PPCODE:
|
| 2532 |
+
XSRETURN_YES;
|
| 2533 |
+
|
| 2534 |
+
|
| 2535 |
+
void
|
| 2536 |
+
zkw_FETCH(attr_hash, attr_key)
|
| 2537 |
+
Net::ZooKeeper::Watch attr_hash
|
| 2538 |
+
SV *attr_key
|
| 2539 |
+
PREINIT:
|
| 2540 |
+
zk_watch_t *watch;
|
| 2541 |
+
char *key;
|
| 2542 |
+
SV *val = NULL;
|
| 2543 |
+
PPCODE:
|
| 2544 |
+
watch = _zkw_get_handle_inner(aTHX_ attr_hash);
|
| 2545 |
+
|
| 2546 |
+
if (!watch) {
|
| 2547 |
+
Perl_croak(aTHX_ "invalid handle");
|
| 2548 |
+
}
|
| 2549 |
+
|
| 2550 |
+
key = SvPV_nolen(attr_key);
|
| 2551 |
+
|
| 2552 |
+
if (strcaseEQ(key, "timeout")) {
|
| 2553 |
+
val = newSVuv(watch->timeout);
|
| 2554 |
+
}
|
| 2555 |
+
else if (strcaseEQ(key, "event")) {
|
| 2556 |
+
val = newSViv(watch->event_type);
|
| 2557 |
+
}
|
| 2558 |
+
else if (strcaseEQ(key, "state")) {
|
| 2559 |
+
val = newSViv(watch->event_state);
|
| 2560 |
+
}
|
| 2561 |
+
|
| 2562 |
+
if (val) {
|
| 2563 |
+
ST(0) = sv_2mortal(val);
|
| 2564 |
+
|
| 2565 |
+
XSRETURN(1);
|
| 2566 |
+
}
|
| 2567 |
+
|
| 2568 |
+
Perl_warn(aTHX_ "invalid element: %s", key);
|
| 2569 |
+
|
| 2570 |
+
XSRETURN_UNDEF;
|
| 2571 |
+
|
| 2572 |
+
|
| 2573 |
+
void
|
| 2574 |
+
zkw_STORE(attr_hash, attr_key, attr_val)
|
| 2575 |
+
Net::ZooKeeper::Watch attr_hash
|
| 2576 |
+
SV *attr_key
|
| 2577 |
+
SV *attr_val
|
| 2578 |
+
PREINIT:
|
| 2579 |
+
zk_watch_t *watch;
|
| 2580 |
+
char *key;
|
| 2581 |
+
PPCODE:
|
| 2582 |
+
watch = _zkw_get_handle_inner(aTHX_ attr_hash);
|
| 2583 |
+
|
| 2584 |
+
if (!watch) {
|
| 2585 |
+
Perl_croak(aTHX_ "invalid handle");
|
| 2586 |
+
}
|
| 2587 |
+
|
| 2588 |
+
key = SvPV_nolen(attr_key);
|
| 2589 |
+
|
| 2590 |
+
if (strcaseEQ(key, "timeout")) {
|
| 2591 |
+
watch->timeout = SvUV(attr_val);
|
| 2592 |
+
}
|
| 2593 |
+
else {
|
| 2594 |
+
int i;
|
| 2595 |
+
|
| 2596 |
+
for (i = 0; i < NUM_WATCH_KEYS; ++i) {
|
| 2597 |
+
if (strcaseEQ(key, zk_watch_keys[i].name)) {
|
| 2598 |
+
Perl_warn(aTHX_ "read-only element: %s", key);
|
| 2599 |
+
|
| 2600 |
+
XSRETURN_EMPTY;
|
| 2601 |
+
}
|
| 2602 |
+
}
|
| 2603 |
+
|
| 2604 |
+
Perl_warn(aTHX_ "invalid element: %s", key);
|
| 2605 |
+
}
|
| 2606 |
+
|
| 2607 |
+
XSRETURN_EMPTY;
|
| 2608 |
+
|
| 2609 |
+
|
| 2610 |
+
void
|
| 2611 |
+
zkw_EXISTS(attr_hash, attr_key)
|
| 2612 |
+
Net::ZooKeeper::Watch attr_hash
|
| 2613 |
+
SV *attr_key
|
| 2614 |
+
PREINIT:
|
| 2615 |
+
zk_watch_t *watch;
|
| 2616 |
+
char *key;
|
| 2617 |
+
int i;
|
| 2618 |
+
PPCODE:
|
| 2619 |
+
watch = _zkw_get_handle_inner(aTHX_ attr_hash);
|
| 2620 |
+
|
| 2621 |
+
if (!watch) {
|
| 2622 |
+
Perl_croak(aTHX_ "invalid handle");
|
| 2623 |
+
}
|
| 2624 |
+
|
| 2625 |
+
key = SvPV_nolen(attr_key);
|
| 2626 |
+
|
| 2627 |
+
for (i = 0; i < NUM_WATCH_KEYS; ++i) {
|
| 2628 |
+
if (strcaseEQ(key, zk_watch_keys[i].name)) {
|
| 2629 |
+
XSRETURN_YES;
|
| 2630 |
+
}
|
| 2631 |
+
}
|
| 2632 |
+
|
| 2633 |
+
XSRETURN_NO;
|
| 2634 |
+
|
| 2635 |
+
|
| 2636 |
+
void
|
| 2637 |
+
zkw_DELETE(attr_hash, attr_key)
|
| 2638 |
+
Net::ZooKeeper::Watch attr_hash
|
| 2639 |
+
SV *attr_key
|
| 2640 |
+
PPCODE:
|
| 2641 |
+
Perl_warn(aTHX_ "deleting elements from hashes of class "
|
| 2642 |
+
WATCH_PACKAGE_NAME " not supported");
|
| 2643 |
+
|
| 2644 |
+
XSRETURN_EMPTY;
|
| 2645 |
+
|
| 2646 |
+
|
| 2647 |
+
void
|
| 2648 |
+
zkw_CLEAR(attr_hash)
|
| 2649 |
+
Net::ZooKeeper::Watch attr_hash
|
| 2650 |
+
PPCODE:
|
| 2651 |
+
Perl_warn(aTHX_ "clearing hashes of class "
|
| 2652 |
+
WATCH_PACKAGE_NAME " not supported");
|
| 2653 |
+
|
| 2654 |
+
XSRETURN_EMPTY;
|
| 2655 |
+
|
| 2656 |
+
|
| 2657 |
+
void
|
| 2658 |
+
zkw_wait(zkwh, ...)
|
| 2659 |
+
Net::ZooKeeper::Watch zkwh
|
| 2660 |
+
PREINIT:
|
| 2661 |
+
zk_watch_t *watch;
|
| 2662 |
+
unsigned int timeout;
|
| 2663 |
+
struct timeval end_timeval;
|
| 2664 |
+
int i, done;
|
| 2665 |
+
struct timespec wait_timespec;
|
| 2666 |
+
PPCODE:
|
| 2667 |
+
watch = _zkw_get_handle_outer(aTHX_ zkwh, NULL);
|
| 2668 |
+
|
| 2669 |
+
if (!watch) {
|
| 2670 |
+
Perl_croak(aTHX_ "invalid handle");
|
| 2671 |
+
}
|
| 2672 |
+
|
| 2673 |
+
if (items > 1 && !(items % 2)) {
|
| 2674 |
+
Perl_croak(aTHX_ "invalid number of arguments");
|
| 2675 |
+
}
|
| 2676 |
+
|
| 2677 |
+
timeout = watch->timeout;
|
| 2678 |
+
|
| 2679 |
+
for (i = 1; i < items; i += 2) {
|
| 2680 |
+
char *key = SvPV_nolen(ST(i));
|
| 2681 |
+
|
| 2682 |
+
if (strcaseEQ(key, "timeout")) {
|
| 2683 |
+
timeout = SvUV(ST(i + 1));
|
| 2684 |
+
}
|
| 2685 |
+
}
|
| 2686 |
+
|
| 2687 |
+
gettimeofday(&end_timeval, NULL);
|
| 2688 |
+
|
| 2689 |
+
end_timeval.tv_sec += timeout / 1000;
|
| 2690 |
+
end_timeval.tv_usec += (timeout % 1000) * 1000;
|
| 2691 |
+
|
| 2692 |
+
wait_timespec.tv_sec = end_timeval.tv_sec;
|
| 2693 |
+
wait_timespec.tv_nsec = end_timeval.tv_usec * 1000;
|
| 2694 |
+
|
| 2695 |
+
pthread_mutex_lock(&watch->mutex);
|
| 2696 |
+
|
| 2697 |
+
while (!watch->done) {
|
| 2698 |
+
struct timeval curr_timeval;
|
| 2699 |
+
|
| 2700 |
+
gettimeofday(&curr_timeval, NULL);
|
| 2701 |
+
|
| 2702 |
+
if (end_timeval.tv_sec < curr_timeval.tv_sec ||
|
| 2703 |
+
(end_timeval.tv_sec == curr_timeval.tv_sec &&
|
| 2704 |
+
end_timeval.tv_usec <= curr_timeval.tv_usec)) {
|
| 2705 |
+
break;
|
| 2706 |
+
}
|
| 2707 |
+
|
| 2708 |
+
pthread_cond_timedwait(&watch->cond, &watch->mutex,
|
| 2709 |
+
&wait_timespec);
|
| 2710 |
+
}
|
| 2711 |
+
|
| 2712 |
+
done = watch->done;
|
| 2713 |
+
|
| 2714 |
+
pthread_mutex_unlock(&watch->mutex);
|
| 2715 |
+
|
| 2716 |
+
if (done) {
|
| 2717 |
+
XSRETURN_YES;
|
| 2718 |
+
}
|
| 2719 |
+
else {
|
| 2720 |
+
XSRETURN_NO;
|
| 2721 |
+
}
|
| 2722 |
+
|
local-test-zookeeper-full-01/afc-zookeeper/zookeeper-contrib/zookeeper-contrib-zkperl/typemap
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Net::ZooKeeper - Perl extension for Apache ZooKeeper
|
| 2 |
+
#
|
| 3 |
+
# Licensed to the Apache Software Foundation (ASF) under one
|
| 4 |
+
# or more contributor license agreements. See the NOTICE file
|
| 5 |
+
# distributed with this work for additional information
|
| 6 |
+
# regarding copyright ownership. The ASF licenses this file
|
| 7 |
+
# to you under the Apache License, Version 2.0 (the
|
| 8 |
+
# "License"); you may not use this file except in compliance
|
| 9 |
+
# with the License. You may obtain a copy of the License at
|
| 10 |
+
#
|
| 11 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 12 |
+
#
|
| 13 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 14 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 15 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 16 |
+
# See the License for the specific language governing permissions and
|
| 17 |
+
# limitations under the License.
|
| 18 |
+
|
| 19 |
+
TYPEMAP
|
| 20 |
+
Net::ZooKeeper T_ZK_HANDLE
|
| 21 |
+
Net::ZooKeeper::Stat T_ZK_HANDLE
|
| 22 |
+
Net::ZooKeeper::Watch T_ZK_HANDLE
|
| 23 |
+
|
| 24 |
+
INPUT
|
| 25 |
+
T_ZK_HANDLE
|
| 26 |
+
if (SvROK($arg) && SvTYPE(SvRV($arg)) == SVt_PVHV &&
|
| 27 |
+
sv_derived_from($arg, \"${ntype}\")) {
|
| 28 |
+
$var = (HV*) SvRV($arg);
|
| 29 |
+
}
|
| 30 |
+
else {
|
| 31 |
+
Perl_croak(aTHX_
|
| 32 |
+
\"$var is not a hash reference of type ${ntype}\");
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
OUTPUT
|
| 36 |
+
T_ZK_HANDLE
|
| 37 |
+
NOT_IMPLEMENTED
|
| 38 |
+
|
local-test-zookeeper-full-01/afc-zookeeper/zookeeper-contrib/zookeeper-contrib-zooinspector/NOTICE.txt
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
src/java/com/nitido/utils/toaster/Toaster.java:
|
| 2 |
+
This java file is copyright by Daniele Piras ("danielepiras80", no email known) released under the Apache Software License 2.0
|
| 3 |
+
It has been downloaded in december 2009 from the CVS web interface of the sourceforge project http://sourceforge.net/projects/jtoaster/ . The web interface to CVS is not available anymore on sourceforge.
|
| 4 |
+
|
| 5 |
+
The icons in src/main/resources/icons are taken from the Tango project
|
| 6 |
+
downloaded from http://tango.freedesktop.org/releases on 2011-09-06.
|
| 7 |
+
The Tango project is public domain.
|
| 8 |
+
|
| 9 |
+
Distribution packagers should not include the icons in the package but rather depend on tango-icon-theme (Debian package name). ZooInspector will then try to get the icons from /usr/share/icons/Tango rather then from its jar file.
|
local-test-zookeeper-full-01/afc-zookeeper/zookeeper-contrib/zookeeper-contrib-zooinspector/README.txt
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
==========================================
|
| 2 |
+
ZooInspector - Browser and Editor for ZooKeeper Instances
|
| 3 |
+
Author: Colin Goodheart-Smithe
|
| 4 |
+
Date: February 2010
|
| 5 |
+
==========================================
|
| 6 |
+
|
| 7 |
+
ZooInspector is a Java Swing based application for browsing and editing ZooKeeper instances.
|
| 8 |
+
|
| 9 |
+
Contents
|
| 10 |
+
--------
|
| 11 |
+
- Features
|
| 12 |
+
- Pre-requisites
|
| 13 |
+
- Build Instructions
|
| 14 |
+
- Using ZooInspector
|
| 15 |
+
- Creating and Using Plugins
|
| 16 |
+
|
| 17 |
+
Features
|
| 18 |
+
--------
|
| 19 |
+
Below is a list of features in the current release of ZooInspector.
|
| 20 |
+
- Load connection settings from a zookeeper properties file
|
| 21 |
+
- Pluggable DataEncryptionManagers to specify how data should be encrypted and decrypted in the Zookeeper instance
|
| 22 |
+
- Browsable tree view of the ZooKeeper instance
|
| 23 |
+
- View the data in a node
|
| 24 |
+
- View the ACLs currently applied to a node
|
| 25 |
+
- View the metadata for a node (Version, Number of Children, Last modified Time, etc.)
|
| 26 |
+
- Pluggable NodeViewers interface
|
| 27 |
+
- Ability to save/load and set default Node Viewers
|
| 28 |
+
|
| 29 |
+
Maven Build Instructions
|
| 30 |
+
-------------------------
|
| 31 |
+
0. Pre-requisites
|
| 32 |
+
- Run "mvn install" in the root directory of the Zookeeper project
|
| 33 |
+
1. Open a command line
|
| 34 |
+
2. cd into this directory
|
| 35 |
+
3. mvn install
|
| 36 |
+
4. To run ZooInspector run zooInspector.cmd (on Windows) or zooInspector.sh (on Linux) (these scripts will
|
| 37 |
+
find the built JAR automatically in the "target" directory as long as you don't move it)
|
| 38 |
+
|
| 39 |
+
Ant Build Instructions
|
| 40 |
+
-----------------------
|
| 41 |
+
0. Pre-requisites
|
| 42 |
+
- The main zookeeper build script must have been run before building this module
|
| 43 |
+
1. Open a command line.
|
| 44 |
+
2. cd into this directory
|
| 45 |
+
3. Run command: ant
|
| 46 |
+
4. ZooInspector will be built to ../../../build/contrib/ZooInspector
|
| 47 |
+
5. Copy zookeeper-3.x.x.jar into the lib sub-directory (if you are using zookeeper-3.3.0.jar it will have been
|
| 48 |
+
copied to this directory during the build
|
| 49 |
+
6. By default the zookeeper.cmd and zookeeper.sh files expect zookeeper-3.3.0.jar. If you are using another version
|
| 50 |
+
you will need to change these files to point to the zookeeper-3.x.x.jar you copied to the lib directory
|
| 51 |
+
7. To run ZooInspector run zooInspector.cmd (on Windows) or zooInspector.sh (on Linux). If you are using
|
| 52 |
+
zookeeper-3.3.0.jar and do not require any classpath changes you can run the zookeeper-dev-ZooInspector.jar
|
| 53 |
+
directly
|
| 54 |
+
|
| 55 |
+
Using ZooInspector
|
| 56 |
+
------------------
|
| 57 |
+
To start ZooInspector run zooInspector.cmd (on Windows) or zooInspector.sh (on Linux). If you are using
|
| 58 |
+
zookeeper-3.3.0.jar and do not require any classpath changes you can run the zookeeper-dev-ZooInspector.jar
|
| 59 |
+
directly.
|
| 60 |
+
|
| 61 |
+
Click the play button on the toolbar to bring up the connection dialog. From here you can enter connection
|
| 62 |
+
information for your zookeeper instance. You can also load the connection properties from a file. This file can
|
| 63 |
+
have the format as a normal zookeeper properties file (i.e. hosts and timeout key-value pairs) and van optional have
|
| 64 |
+
an encryptionManager key-value pair to specify the DataEncryptionManager to use for this connection
|
| 65 |
+
(DataEncryptionManagers are explained in further detail in the 'Creating and Using Plugins' section below). You can
|
| 66 |
+
also set the entered information as the defaults so that when you first start ZooInspector these settings are
|
| 67 |
+
automatically loaded into this dialog. Pressing the OK button with connect to your ZooKeeper instance and show the
|
| 68 |
+
current node tree on the left of the main panel.
|
| 69 |
+
|
| 70 |
+
Clicking a node in the node tree will load the data for that node into the node viewers. Three node viewers are
|
| 71 |
+
currently distributed with ZooInspector:
|
| 72 |
+
1. Node Data - This enables you to see the data current stored on that node. This data can be modified and
|
| 73 |
+
saved. The data is decrypted and encrypted using the DataEncryptionManager specified on the connection
|
| 74 |
+
dialog.
|
| 75 |
+
2. Node Metadata - This enables you to see the metadata associated with this node. This is essentially the data
|
| 76 |
+
obtained from the Stat object for this node.
|
| 77 |
+
3. Node ACLs - This allows you to see the ACLs currently applied to this node. Currently there is no ability
|
| 78 |
+
to change the ACLs on a node, but it is a feature I would like to add.
|
| 79 |
+
Other custom Node Viewers can be added, this is explained in the 'Creating and Using Plugins' section below.
|
| 80 |
+
|
| 81 |
+
|
| 82 |
+
Creating and Using Plugins
|
| 83 |
+
--------------------------
|
| 84 |
+
There are two types of plugin which can be used with ZooInspector:
|
| 85 |
+
1. DataEncryptionManager - This specifies how data should be encrypted and decrypted when working with a
|
| 86 |
+
zookeeper instance.
|
| 87 |
+
2. ZooInspectorNodeViewer - This is a GUI panel which provides a view of visualisation on a node.
|
| 88 |
+
More information on these interfaces can be found in the javadocs for this module.
|
| 89 |
+
|
| 90 |
+
To use a plugin in ZooInspector, build the plugin to a jar and copy the jar to the lib sub-directory. Edit the
|
| 91 |
+
zooInspector.cmd and/or zooInspector.sh files to include your new jar on the classpath and run ZooInspector.
|
| 92 |
+
|
| 93 |
+
For DataEncryptionManagers, click the play button to open the connection dialog and enter the full class name of
|
| 94 |
+
your DataEncryptionManager in the 'Data Encryption Manager' field. You can make this Data Encryption Manager the
|
| 95 |
+
default by clicking 'Set As Default'. Click the 'OK' button to instantiate and use your plugin.
|
| 96 |
+
|
| 97 |
+
For ZooInspectorNodeViewers, Click the 'Change Node Viewers' button on the toolbar (looks like a tree with a pencil)
|
| 98 |
+
and enter the full classname for your Node Viewer in the field left of the 'Add' button, then click the 'Add'
|
| 99 |
+
button. The Node Viewer will be instantiated and should appear in the list. You can change the order of the Node
|
| 100 |
+
viewers by clicking the up and down buttons and delete a Node Viewer by clicking the delete button. You can save
|
| 101 |
+
to configuration to a file or set it as the default if necessary. Then click the 'OK' button and your Node Viewer
|
| 102 |
+
should appear in the tabs on the right of the main panel.
|
local-test-zookeeper-full-01/afc-zookeeper/zookeeper-contrib/zookeeper-contrib-zooinspector/TODO
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
- replace JToaster with standard notifications, see:
|
| 2 |
+
http://www.galago-project.org/specs/notification/
|
| 3 |
+
http://stackoverflow.com/questions/857154/freedesktop-org-notifications-in-java
|
| 4 |
+
DBus and Java:
|
| 5 |
+
http://bolta-gecko.blogspot.com/2009/06/using-d-bus-in-java.html
|
| 6 |
+
http://dbus.freedesktop.org/doc/dbus-java/ (packaged in Debian)
|
| 7 |
+
|
| 8 |
+
- properly respect
|
| 9 |
+
http://standards.freedesktop.org/desktop-entry-spec/desktop-entry-spec-latest.html
|
| 10 |
+
http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html
|
| 11 |
+
http://standards.freedesktop.org/icon-theme-spec/icon-theme-spec-latest.html
|
| 12 |
+
|
| 13 |
+
- Rename classes to avoid redundant "ZooInspector" prefix.
|
| 14 |
+
|
| 15 |
+
- Ant build file has hard coded log4j dependency. (ZK will move to maven anyways...)
|
| 16 |
+
|
| 17 |
+
- make directory for config files configurable via commandline parameter
|
| 18 |
+
|
| 19 |
+
- Clean up the code! :-)
|
local-test-zookeeper-full-01/afc-zookeeper/zookeeper-contrib/zookeeper-contrib-zooinspector/zooInspector-dev.sh
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/sh
|
| 2 |
+
|
| 3 |
+
# Licensed to the Apache Software Foundation (ASF) under one or more
|
| 4 |
+
# contributor license agreements. See the NOTICE file distributed with
|
| 5 |
+
# this work for additional information regarding copyright ownership.
|
| 6 |
+
# The ASF licenses this file to You under the Apache License, Version 2.0
|
| 7 |
+
# (the "License"); you may not use this file except in compliance with
|
| 8 |
+
# the License. You may obtain a copy of the License at
|
| 9 |
+
#
|
| 10 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 11 |
+
#
|
| 12 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 13 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 14 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 15 |
+
# See the License for the specific language governing permissions and
|
| 16 |
+
# limitations under the License.
|
| 17 |
+
|
| 18 |
+
java -cp ../../build/contrib/ZooInspector/*:../../../build/*:../../../build/lib/*:lib org.apache.zookeeper.inspector.ZooInspector
|
local-test-zookeeper-full-01/afc-zookeeper/zookeeper-contrib/zookeeper-contrib-zooinspector/zooInspector.cmd
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
@echo off
|
| 2 |
+
@rem Licensed to the Apache Software Foundation (ASF) under one or more
|
| 3 |
+
@rem contributor license agreements. See the NOTICE file distributed with
|
| 4 |
+
@rem this work for additional information regarding copyright ownership.
|
| 5 |
+
@rem The ASF licenses this file to You under the Apache License, Version 2.0
|
| 6 |
+
@rem (the "License"); you may not use this file except in compliance with
|
| 7 |
+
@rem the License. You may obtain a copy of the License at
|
| 8 |
+
@rem
|
| 9 |
+
@rem http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
@rem
|
| 11 |
+
@rem Unless required by applicable law or agreed to in writing, software
|
| 12 |
+
@rem distributed under the License is distributed on an "AS IS" BASIS,
|
| 13 |
+
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 14 |
+
@rem See the License for the specific language governing permissions and
|
| 15 |
+
@rem limitations under the License.
|
| 16 |
+
|
| 17 |
+
@rem Get the path to the directory containing this script
|
| 18 |
+
SET SCRIPT_DIR=%~dp0
|
| 19 |
+
|
| 20 |
+
@rem Get the path to the uber jar for this tool
|
| 21 |
+
@rem (Requires "mvn install" or "mvn package" be run first)
|
| 22 |
+
set JAVA_LIB=
|
| 23 |
+
for /F %%f in ('dir /b "%SCRIPT_DIR%\target\zookeeper-contrib-zooinspector-*-jar-with-dependencies.jar" 2^>nul') do (
|
| 24 |
+
set JAVA_LIB=%SCRIPT_DIR%target\%%f
|
| 25 |
+
)
|
| 26 |
+
java -jar %JAVA_LIB%
|
local-test-zookeeper-full-01/afc-zookeeper/zookeeper-contrib/zookeeper-contrib-zooinspector/zooInspector.sh
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/sh
|
| 2 |
+
|
| 3 |
+
# Licensed to the Apache Software Foundation (ASF) under one or more
|
| 4 |
+
# contributor license agreements. See the NOTICE file distributed with
|
| 5 |
+
# this work for additional information regarding copyright ownership.
|
| 6 |
+
# The ASF licenses this file to You under the Apache License, Version 2.0
|
| 7 |
+
# (the "License"); you may not use this file except in compliance with
|
| 8 |
+
# the License. You may obtain a copy of the License at
|
| 9 |
+
#
|
| 10 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 11 |
+
#
|
| 12 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 13 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 14 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 15 |
+
# See the License for the specific language governing permissions and
|
| 16 |
+
# limitations under the License.
|
| 17 |
+
|
| 18 |
+
# Get the path to the directory containing this script
|
| 19 |
+
SCRIPT_DIR=$(dirname "$0")
|
| 20 |
+
|
| 21 |
+
# Get the path to the uber jar for this tool
|
| 22 |
+
# (Requires "mvn install" or "mvn package" be run first)
|
| 23 |
+
JAVA_LIB=`ls ${SCRIPT_DIR}/target/zookeeper-contrib-zooinspector-*-jar-with-dependencies.jar`
|
| 24 |
+
|
| 25 |
+
java -jar "${JAVA_LIB}"
|
local-test-zookeeper-full-01/afc-zookeeper/zookeeper-server/src/test/resources/data/buffersize/set/version-2/log.1
ADDED
|
Binary file (51.2 kB). View file
|
|
|